「CF305X」Codeforces Round #184 (Div. 2)
A. Strange Addition
考虑0的个数,是否存在100,是否同时存在X0和0X
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<map> #include<set> #include<cmath> #include<deque> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define mod 1000000007 #define ll long long 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; } int n,f1,f2,f3,mark; int a[105]; vector<int>ans; int main() { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); if(a[i]==0)ans.push_back(a[i]); else if(a[i]==100&&!mark) { ans.push_back(a[i]); mark=1; } else { f3=a[i]; if(a[i]%10==0)f1=a[i]; else if(a[i]<10)f2=a[i]; } } if(f1&&f2)ans.push_back(f1),ans.push_back(f2); else if(f3)ans.push_back(f3); printf("%d\n",(int)ans.size()); for(int i=0;i<ans.size();i++) printf("%d ",ans[i]); return 0; } |
B. Continued Fractions
http://www.cnblogs.com/scau20110726/archive/2013/06/09/3130198.html
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<map> #include<set> #include<cmath> #include<deque> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define mod 1000000007 #define ll long long 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 p,q,n; ll a[105]; int main() { p=read();q=read();n=read(); for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++) { if(!q||a[i]>(p/q)){puts("NO");return 0;} ll t=q;q=p-a[i]*q;p=t; } if(q)puts("NO"); else puts("YES"); return 0; } |
C. Ivan and Powers of Two
感觉就是个模拟题0。0,每个数字再往后若干位开始一定就会是连续一段0
用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 |
#include<map> #include<set> #include<cmath> #include<deque> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 2147483647 #define mod 1000000007 #define ll long long 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; } int n,ans; int a[100005]; map<int,int>b; int main() { n=read(); for(int i=1;i<=n;i++)a[i]=read(); ans=a[1];a[n+1]=inf; for(int i=1;i<=n+1;i++) { if(a[i]!=a[i-1]&&i!=1) for(int j=a[i-1];j<a[i];j++) { if(b[j]<2) { if(i!=n+1)ans+=a[i]-j-1; break; } while(b[j]>=2){b[j]-=2;b[j+1]++;} if(!b[j])ans++; } b[a[i]]++; } printf("%d\n",ans); return 0; } |
D. Olya and Graph
性质1:从i到i+1的边一定要存在。
性质2:从i到j之间最多只能有一条跳跃边。
根据性质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 |
#include<map> #include<set> #include<cmath> #include<cstdio> #include<cstring> #include<vector> #include<iostream> #define mod 1000000007 #define ll long long #define add(i,a,b,c,j,val) (f[i][min(a,h)][min(b,h)][min(c,h)][j]+=val)%=mod; using namespace std; ll 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,m,K,tot,l,r; int bin[1000005]; int main() { n=read();m=read();K=read();l=n; bin[0]=1;for(int i=1;i<=K;i++)bin[i]=(bin[i-1]<<1)%mod; for(int i=1;i<=m;i++) { int u=read(),v=read(); if(v-u>1) { if(v-u!=K+1){puts("0");return 0;} l=min(l,u);r=max(r,u);tot++; } } if(l==n) { int ans=1; for(int i=1;i<=n-K+1;i++) ans=(ans+bin[min(K,n-i-K-1)])%mod; printf("%d\n",ans); } else { int ans=0; for(int i=1;i<=n-K+1;i++) if(i<=l&&i+K>=r) ans=(ans+bin[min(K,n-i-K-1)-tot+(i==l)])%mod; printf("%d\n",ans); } return 0; } |
Subscribe