Codeforces Round #436 (Div. 2) A,B,D
A. Fair Game
题目链接:http://codeforces.com/contest/864/problem/A
水题
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<stack> #include<map> #include<vector> #include<set> using namespace std; const int MAX=1e5+10; const double eps=1e-6; const double mod=1e9+7; #define INF 0x7fffffff #define ll long long #define edl putchar('\n') #define useit ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define FOR(i,a,b) for(ll i=a;i<=b;i++) #define ROF(i,a,b) for(ll i=a;i>=b;i--) #define mst(a) memset(a,0,sizeof(a)) #define mstn(a,n) memset(a,n,sizeof(a)) #define lowbit(x) x&(-x) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 //struct num{int v,i;}l[MAX],r[MAX]; //bool cmp(const num &x, const num &y){return x.v<y.v;} int main() { int n,a[MAX],b,t=0,s1=999,s2=9999; FOR(i,0,100)a[i]=0; cin>>n; FOR(i,1,n) { cin>>b; if(!a[b]) t++; a[b]++; } if(t==2) { FOR(i,1,100) if(a[i]){s1=i;break;} ROF(i,100,1) if(a[i]){s2=i;break;} if(a[s1]==a[s2]&&s1!=s2) cout<<"YES"<<endl<<s1<<" "<<s2<<endl; else cout<<"NO"<<endl; } else cout<<"NO"<<endl; }
B. Polycarp and Letters
题目链接:http://codeforces.com/contest/864/problem/B
水题,写太急了,忘了考虑全是小写字母的情况,wa了两发血亏。
#include<bits/stdc++.h> using namespace std; #define ll long long const int inf = 1e9+7; const int M = 1e5+9; map<char,int>mp; int main() { int n,maxx; char s[400]; cin>>n; for(int i=0;i<n;i++) cin>>s[i]; maxx = -inf; int ans = 0; for(char i = 'a';i<='z';i++){ mp[i] = 0; } for(int i=0;i<n;i++){ if(s[i]>='a'&&s[i]<='z'){ if(mp[s[i]]==0) { ans++; mp[s[i]]=1; } } else{ maxx = max(ans,maxx); ans = 0; for(char i = 'a';i<='z';i++){ mp[i] = 0; } } } maxx = max(ans,maxx); cout<<maxx<<endl; return 0; }
D. Make a Permu!
题目链接:http://codeforces.com/contest/864/problem/D
题目有点水,直接暴力过了。。
#include<bits/stdc++.h> using namespace std; #define ll long long const int inf = 1e9+7; const int M = 2e5+9; map<int,int>mp; int a[M],flag[M]; int main() { int n,maxx,i,j; cin>>n; maxx = -inf; memset(flag,0,sizeof(flag)); int cnt = 0; for(i=0;i<n;i++){ cin>>a[i]; mp[a[i]]++; if(mp[a[i]]>1) cnt++; maxx = max(a[i],maxx); } int l=0; for(i=0;i<n;i++){ if(mp[a[i]]>1){ for(j=l+1;j<=M;j++){ if(mp[j]==0){ mp[j]==1; l = j;break; } } //cout<<l<<endl; if(l<a[i]){ //cout<<mp[a[i]]<<endl; mp[a[i]]-=1,a[i]=l; //之前这里先替换再标记。搞得wa了一发,血亏。。还好学长出了发神样例查到了 //cout<<mp[a[i]]<<endl; } else{ if(flag[a[i]]==1){ mp[a[i]]--,a[i]=l; } else{ mp[l]==0;l--; flag[a[i]] = 1; } } } } cout<<cnt<<endl; for(i=0;i<n;i++){ cout<<a[i]<<" "; } cout<<endl; return 0; }