Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework
A. Meeting of Old Friends
模拟
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; ll l1,r1,l2,r2,k; int main(int argc, const char * argv[]) { cin>>l1>>r1>>l2>>r2>>k; ll l=max(l1,l2),r=min(r1,r2); ll ans=r-l+1; if(k>=l&&k<=r) ans--; if(ans<0) cout<<0; else cout<<ans; return 0; }
B. Filya and Homework
YES最多三个数,成等差数列
分情况讨论
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,a,cnt=0,t[5]; int main(int argc, const char * argv[]) { n=read(); for(int i=1;i<=n;i++){ a=read(); int flag=0; for(int j=1;j<=cnt;j++) if(a==t[j]){flag=1;break;} if(cnt==3&&flag==0){cout<<"NO";return 0;} if(cnt<3&&flag==0) t[++cnt]=a; } if(cnt<3){cout<<"YES";return 0;} sort(t+1,t+1+3); if(t[2]-t[1]==t[3]-t[2]) printf("YES"); else printf("NO"); return 0; }
Codeforces#372(Div.2)716A. Crazy Computer |716B. Complete the Word[模拟]
A. Crazy Computer
非常水的模拟
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int n,c,a,ans=0,last=0; int main(int argc, const char * argv[]) { n=read();c=read(); last=read();ans=1; for(int i=2;i<=n;i++){ a=read(); if(a-last<=c){last=a;ans++;} else {last=a;ans=1;} } printf("%d",ans); return 0; }
B. Complete the Word
可以枚举n然后扫26个,也可以用队列糊O(n)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=5e4+5; char s[N]; int n,flag=0,lst[30],vis[30],cnt=0,st,ed; int main(int argc, const char * argv[]) { scanf("%s",s+1); n=strlen(s+1); if(n<26){printf("-1");return 0;} for(int i=1;i<=n-25;i++){ memset(vis,0,sizeof(vis)); flag=1;cnt=0; for(int j=i;j<=i+25;j++) if(s[j]!='?'){ int a=s[j]-'A'; if(vis[a]){flag=0;break;} vis[a]=1; } if(flag){st=i;ed=i+25;break;} } if(!flag){printf("-1");return 0;} memset(vis,0,sizeof(vis)); for(int i=st;i<=ed;i++) if(s[i]!='?') vis[s[i]-'A']=1; for(int i=0;i<26;i++) if(!vis[i]) lst[++cnt]=i; int p=0; for(int i=st;i<=ed;i++) if(s[i]=='?') s[i]=lst[++p]+'A'; for(int i=1;i<=n;i++){ if(s[i]=='?') printf("A"); else printf("%c",s[i]); } return 0; }
Codeforces#373(Div.2)719A. Vitya in the Countryside |719B. Anatoly and Cockroaches[模拟]
Copyright:http://www.cnblogs.com/candy99/