标签:方式 return strong 个人 space ble blank names http
A:http://codeforces.com/contest/1475/problem/A
题意:
判断n是否有>1的奇数因子
解析:
不断比2即可。
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> using namespace std; const int maxn = 3e5+50; const int inf=99999999; typedef long long ll; int main() { int t; cin>>t; while(t--) { ll n; cin>>n; if(n==2) cout<<"NO"<<endl; else if(n%2!=0) cout<<"YES"<<endl; else { int ok = 0; while(n) { ll md=n/2; if(md%2!=0&&md>1) { ok=1;break; } n=n/2; } if(n==1) cout<<"NO"<<endl; else if(ok) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; } //ababab
B:http://codeforces.com/contest/1475/problem/B
题意:
判断一个数是否由若干个2020和2021组成
解析:
若n符合,为:2020x+2021y==n
而2021==2020+1
则:2020g+j==n
这个j一定是<=g的
写麻烦了。。。暴力跑了,但是时间还算过得去
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> using namespace std; const int maxn = 3e5+50; const int inf=99999999; typedef long long ll; int main() { int t; cin>>t; while(t--) { int n ; cin>>n; int ok = 0; for(int i=1;i<=500;i++) { if(i*2020<=n) { int md=n-i*2020; if(md<=i) { ok=1;break; } } } if(ok) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } //ababab
C:http://codeforces.com/contest/1475/problem/C
题意:
有a位男士和b位女士参加舞会,有k对关系,表示两个人可以共舞。然后要取出四个人,组成两支舞队,有几种方式
解析:
开俩vector v1[],v2[]
v1[a]=b表示男士a可与b跳舞
v2[b]=a表示女士b可与a跳舞
那么遍历每一对关系,若a与b可跳舞,那么v1[a].size即为与a有关的对数,v2[b].size即为与b有关的对数,v1[a].size+v2[b].size-1即为与a-b对冲突的对数(-1的原因是本身a-b算一对合法)。k-它们即为可选对数。
结尾记得比2
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<map> using namespace std; const int maxn = 2e5+50; const int inf=99999999; typedef long long ll; int vv1[maxn],vv2[maxn]; vector<int>v1[maxn]; vector<int>v2[maxn]; int main() { int t; cin>>t; while(t--) { int a,b,k; cin>>a>>b>>k; for(int i=1;i<=a;i++) v1[i].clear(); for(int i=1;i<=b;i++) v2[i].clear(); for(int i=1;i<=k;i++) { cin>>vv1[i]; } for(int i=1;i<=k;i++) { cin>>vv2[i]; v1[vv1[i]].push_back(vv2[i]); v2[vv2[i]].push_back((vv1[i])); } ll ans = 0 ; for(int i=1;i<=k;i++) { ans+=k-(v1[vv1[i]].size()+v2[vv2[i]].size()-1); } cout<<ans/2<<endl; } return 0; } //ababab
Codeforces Round #697 (Div. 3)(A->C)
标签:方式 return strong 个人 space ble blank names http
原文地址:https://www.cnblogs.com/liyexin/p/14337755.html