https://codeforces.com/contest/1234/problem/A
A. Equalize Prices Again
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main(){ 5 int n,a; 6 int t; 7 cin>>t; 8 ll sum = 0,ans; 9 while(t--){ 10 cin>>n;sum = 0; 11 for(int i = 0;i < n;++i){ 12 cin>>a;sum+=a; 13 } 14 ans = sum/n; 15 if(sum%n)ans+=1; 16 cout<<ans<<endl; 17 } 18 }
https://codeforces.com/contest/1234/problem/B1
B1. Social Network (easy version)
https://codeforces.com/contest/1234/problem/B2
B2. Social Network (hard version)
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll a; int n ,k ,now=0,fi=0; vector<ll>s; map<ll,int>mp; int main(){ cin>>n>>k; for(int i = 0;i < n;++i){ cin>>a; if(mp[a]==0){ mp[a]=1;s.push_back(a); if(now<k){ now++; } else if(now==k){ mp[s[fi]]=0;fi++; } } } cout<<now<<endl; int l =s.size()-1; int cnt=0; while(cnt<now&&l>=0){ if(mp[s[l]])cnt++,cout<<s[l]<<" "; l--; } cout<<endl; return 0; }
https://codeforces.com/contest/1234/problem/C
C. Pipes
旋转一遍发现前两种其实是不同方向摆放的一种管道,后四个同理,也就是只有两个管道,一个是直流另一个会变向,然后问题就很简单了。
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 int main(){ 6 int t,n; 7 cin>>t; 8 while(t--){ 9 cin>>n; 10 string a[3];cin>>a[0]>>a[1]; 11 int now=0,flag =1; 12 for(int i = 0;i <n;++i){ 13 if(a[now][i]=='1'||a[now][i]=='2')continue; 14 else{ 15 now=1-now; 16 if(a[now][i]=='1'||a[now][i]=='2'){ 17 flag=0;break; 18 } 19 } 20 } 21 if(flag==0||now==0)cout<<"no"<<endl; 22 else cout<<"yes"<<endl; 23 } 24 return 0; 25 }
https://codeforces.com/contest/1234/problem/D
D. Distinct Characters Queries
用线段树维护不同字母的个数orz学到了新东西,待会再看看set的做法?