Codeforces Round 944 (Div. 4)
A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include<bits/stdc++.h> #define ll long long using namespace std; void solve() { int x,y; cin>>x>>y; cout<<min(x,y)<<" "<<max(x,y)<<'\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
B
找到第一个不同的就可以了
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
| #include<bits/stdc++.h> #define ll long long using namespace std; void solve() { string s; cin>>s; for(int i=0;i<s.length();i++) if(s[i]!=s[0]) { cout<<"YES"<<'\n'; swap(s[0],s[i]); cout<<s<<'\n'; return ; } cout<<"NO"<<'\n'; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
C
可以想到如果要满足不相交的话,就一定有2个点的圆弧段包含另外两个点的圆弧段
因此数据范围很小直接模拟这个走地图的过程就可以了
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include<bits/stdc++.h> #define ll long long using namespace std; void solve() { int a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3]; if(a[0]<a[1]) { swap(a[0],a[1]); } if(a[2]<a[3]) { swap(a[2],a[3]); } int x=a[0]; int y=a[1]; int z=a[2]; int f=a[3]; bool flag=0,flag1=0; while(x!=y) { x++; if(x==13) { x=1; } if(x==a[2]) { flag=1; } if(x==a[3]) { flag1=1; } } if(flag&&flag1) { cout<<"NO"<<'\n'; return ; } x=a[0]; flag=0; flag1=0; while(y!=x) { y++; if(y==13) { y=1; } if(y==a[2]) { flag=1; } if(y==a[3]) { flag1=1; }
} if(flag&&flag1) { cout<<"NO"<<'\n'; return ; }
cout<<"YES"<<'\n';
}
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
D
算出01串连续的数量,找到第一个01出现
如果有就可以减去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
| #include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e6; int a[N]; void solve() { string s; cin>>s; int cnt=0; int ans=1; int cnt_0=0; int cnt_1=0; for(int i=0;i<s.length()-1;i++) { if(s[i]!=s[i+1]) { a[++cnt]=s[i]-'0'; }
} if(s[s.length()-1]!=a[cnt]) { a[++cnt]=s[s.length()-1]-'0'; } for(int i=1;i<=cnt-1;i++) { if(a[i]==0&&a[i+1]==1) { cout<<cnt-1<<'\n'; return ; } } cout<<cnt<<'\n';
}
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
E
本题启发的是精度问题,可以不开小数点要尽量不开小数点
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 57 58
| #include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e6; ll a[N]; ll b[N]; void solve() { int n,k,q; cin>>n>>k>>q; for(int i=1;i<=k;i++) { cin>>a[i]; } for(int i=1;i<=k;i++) { cin>>b[i]; } while(q--) { int x; cin>>x; if(x==0) { cout<<0<<' '; continue; } int i=lower_bound(a+1,a+k+1,x)-a; if(x==a[i]) { cout<<b[i]<<' '; continue; } if(a[i]<x) { i++; } cout<<(ll)(b[i-1]+(b[i]-b[i-1])*(x-a[i-1])/(a[i]-a[i-1]))<<' '; } cout<<'\n';
}
signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
F
本人的nt做法,直接枚举一个横坐标找到两个纵坐标
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<bits/stdc++.h> #define ll long long #define int long long using namespace std; const int N=1e6;
void solve() {
int r; cin>>r;
int ans=0; int x=r+1; for(int i=1;i<=r;i++) { int y=sqrt(r*r-i*i); int z=(sqrt(x*x-i*i));
int a1,a2; if(y*y+i*i==r*r) { a1=y-1; } else { a1=y; } if(z*z+i*i==x*x) { a2=z-1; } else { a2=z; }
ans+=a2-a1; } cout<<ans*4+4-4<<'\n'; }
signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|
队友的神仙做法
节省码量:
1 2 3 4 5 6 7 8 9 10 11 12
| void solve(){ int n;cin>>n; int cnt=0; int y=n; for(int i=0;y>0;i++){ if(int(hypot(i,y))==n)cnt++; else{ if(int(hypot(i,y))>n){i-=2;y--;} } } cout<<4*cnt<<"\n"; }
|
如果大于减去1的同时回到上一次看看是不是满足
因为一开始自增了,现在需要+2
G
本题你观察异或小于4因此的话就可以得出一个结论就是后2位不同,其他位都相同就是满足答案的。
然后我们就要找到所有除去最后面两位的数字相同的放进一个Map里面,然后由于其他都是可以互换位置的,这个我不会证明,但大概想一下其实还是可以得到的,因此就是排序。
所以难点就只剩下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 43 44 45 46 47 48 49
| #include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e6; ll a[N]; ll ans[N]; bool cmp(int x,int y) { return a[x]<a[y]; } void solve() { int n; cin>>n; map<ll,vector<ll> >mp; for(int i=1;i<=n;i++) { cin>>a[i]; mp[a[i]>>2].push_back(i); } for(auto &[x,v]:mp) { vector<ll>b=v; sort(b.begin(),b.end(),[&](int i,int j){return a[i]<a[j];}); for(int i=0;i<b.size();i++) { ans[v[i]]=a[b[i]]; } } for(int i=1;i<=n;i++) { cout<<ans[i]<<' '; } cout<<'\n';
}
signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { solve(); } return 0; }
|