牛客周赛 Round 60

A

模拟即可。

1
2
3
4
5
6
7
8
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
cout<<(x^x^x^x);
}

B

观察一下情况:

n==m+1时候,就全部都可以

n==m时候也是全部都可以

n>m时候也就是输出2*m+1即可,这是最大的情况了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
if(n<m)
{
swap(n,m);
}
if(n==m+1)
{
cout<<n+m<<'\n';
}
else if(n==m)
{
cout<<2*m<<'\n';
}
else
{
cout<<2*m+1<<'\n';
}
}

C

记录4个map即可,代码可读性还算可以。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
int n,m;
cin>>n>>m;
map<int,int>mp1;
map<int,int>mp2;
map<int,int>mp3;
map<int,int>mp4;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
if(!mp1[x])
{
mp1[x]=y;
mp2[x]=y;
}
if(!mp3[y])
{
mp3[y]=x;
mp4[y]=x;
}
mp3[y]=max(mp3[y],x);
mp4[y]=min(mp4[y],x);
mp1[x]=max(mp1[x],y);
mp2[x]=min(mp2[x],y);

}
int ans=0;
for(auto &[x,y]:mp1)
{
ans=max(ans,abs(mp1[x]-mp2[x]));
}
for(auto &[x,y]:mp3)
{
ans=max(ans,abs(mp3[y]-mp4[y]));
}
cout<<ans<<'\n';
}

D

用一种类似于dp的思路,sum表示大于可以表示小于或等于sum的数字,如果有a[i],那么可以表示的数字就为sum+a[i]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;

void solve() {
int n;
std::cin >> n;

std::vector<int> a(n + 1);
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
std::sort(a.begin() + 1, a.end());
i64 sum = 0;
for (int i = 1; i <= n; i++) {
if(sum >= a[i] - 1) {
sum += a[i];
}
}
if (sum >= n) {
std::cout << "Cool!" << '\n';
}
else {
std::cout << sum + 1 << '\n';
}
}

signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);

i64 t = 1;
std::cin >> t;
while (t--) {
solve();
}
}

E

组合数板子。

C(n-2,m-1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;
const int maxn=1e6+5;
const ll mod=1e9+7;
ll inv[maxn], fac[maxn]; //分别表示逆元和阶乘
//快速幂
ll quickPow(ll a,ll b){
ll ans=1;
while(b){
if(b&1)
ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}

void init(){
//求阶乘
fac[0]=1;
for(int i=1;i<maxn;i++){
fac[i]=fac[i-1]*i%mod;
}
//求逆元
inv[maxn-1]=quickPow(fac[maxn-1],mod-2);
for(int i=maxn-2;i>=0;i--){
inv[i]=inv[i+1]*(i+1)%mod;
}
}
ll C(int n,int m){
if(m>n){
return 0;
}
if(m==0)
return 1;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void solve() {
int n,m;
cin>>n>>m;
cout<<C(n-2,m-1)<<'\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); // 优化输入输出
int t;
init();
cin>>t;
while(t--)
solve();
return 0;
}