「codechefCHEFGR」NOIP2014赛前刷水
赛前不知道做啥,不想打游戏,就找点easy的题练手,水了7题。。。
「codechefCHEFGR」 Chef and Ground
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #define ll long long using namespace std; 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 T,n,m,mx; int a[105]; int main() { T=read(); while(T--) { n=read();m=read(); mx=0; for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++)mx=max(a[i],mx); for(int i=1;i<=n;i++) m-=(mx-a[i]); if(m>=0&&m%n==0)puts("Yes"); else puts("No"); } return 0; } |
「codechefPRPOTION」Magical Girl and Colored Liquid Potions
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #define ll long long using namespace std; 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 T; int a1,a2,a3,m; int mx[5]; priority_queue<int,vector<int> >q; int main() { T=read(); while(T--) { a1=read();a2=read();a3=read();m=read(); memset(mx,0,sizeof(mx)); while(a1--) { int x=read(); mx[1]=max(mx[1],x); } while(a2--) { int x=read(); mx[2]=max(mx[2],x); } while(a3--) { int x=read(); mx[3]=max(mx[3],x); } for(int i=1;i<=3;i++) q.push(mx[i]); for(int i=1;i<=m;i++) { int x=q.top();q.pop(); q.push(x/2); } printf("%d\n",q.top()); while(!q.empty())q.pop(); } return 0; } |
「codechefFATCHEF」Remy paints the fence
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #define ll long long using namespace std; 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 T,n; ll ans; int a[100005]; int main() { T=read(); while(T--) { n=read(); int now=0;ans=0; for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++) { ans+=abs(now); now+=a[i]; } cout<<ans<<endl; } return 0; } |
「codechefCHEFLR」Chef and Left-Right
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #define ll long long #define inf 1000000000 #define mod 1000000007 using namespace std; int T,n; char ch[100005]; 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 main() { T=read(); while(T--) { scanf("%s",ch); n=strlen(ch); int ans=1; for(int i=0;i<n;i++) { if(i&1)ans=ans*2; else ans=ans*2+1; if(ch[i]=='l')ans--; else ans++; ans%=mod; } printf("%d\n",ans); } return 0; } |
「codechefDISCHAR」Distinct Characters Subsequence
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #include<map> #define ll long long #define inf 1000000000 #define mod 1000000007 using namespace std; int T; 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; } map<char,int> a; int n; char ch[100005]; int main() { T=read(); while(T--) { a.clear(); int ans=0; scanf("%s",ch); n=strlen(ch); for(int i=0;i<n;i++) { int t=a[ch[i]]; if(!t) { a[ch[i]]++; ans++; } } printf("%d\n",ans); } return 0; } |
「codechefPRPALN」 Let us construct palindrome
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<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #include<map> #define ll long long #define inf 1000000000 #define mod 1000000007 using namespace std; int T,n; 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; } char a[100005],b[100005]; int cal() { for(int i=1;i<=n;i++) if(a[i]!=a[n-i+1])return i; return (n+1)/2; } bool jud(int x) { int top=0; for(int i=1;i<=n;i++) if(i!=x)b[++top]=a[i]; for(int i=1;i<=top;i++) if(b[i]!=b[top-i+1])return 0; return 1; } int main() { T=read(); while(T--) { scanf("%s",a+1); n=strlen(a+1); int t1=cal(),t2=n-t1+1; if(jud(t1)||jud(t2))puts("YES"); else puts("NO"); } return 0; } |
「codechefCHEFSEG」Chef and Segment Game
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 |
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> #include<cmath> #include<map> #define ll long long #define inf 1000000000 #define mod 1000000007 using namespace std; ll read() { ll 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; } ll bin[40],K; int T; double x; int main() { bin[0]=1;for(int i=1;i<40;i++)bin[i]=bin[i-1]<<1; T=read(); while(T--) { x=read();K=read(); int now=0; while(bin[now+1]<=K)now++; K-=bin[now]-1; printf("%lf\n",x*(K*2-1)/bin[now+1]); } return 0; } |
Subscribe