文章目录
牛客周赛 Round 60(思维、逆元、组合数、概率DP)
F题,概率DP不会,学了再补
A. 困难数学题
- x ^ x = 0
- 0 ^ x = x
- ^ 表示二进制异或
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << 0 << endl;
return 0;
}
B. 构造序列
注意是ABAB,还是ABABA
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll a, b;
cin >> a >> b;
cout << min(a, b) * 2 + (a != b) << endl;
return 0;
}
C. 连点成线
统计每行每列出现的最大值和最小值,做差取max即可,
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> row[maxn], column[maxn];
int main(){
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
row[x].push_back(y);
column[y].push_back(x);
}
int res = 0;
for(int i = 1; i <= n; i++){
if(row[i].size() > 1){
sort(row[i].begin(), row[i].end());
res = max(res, *(row[i].end() - 1) - row[i][0]); // row[i].end() 是指针,表示row[i]最后一个元素的后一位的地址
}
if(column[i].size() > 1){
sort(column[i].begin(), column[i].end());
res = max(res, *(column[i].end() - 1) - column[i][