http://codeforces.com/contest/199
A 很水的题,仔细分析即可,每个斐波那契数 f1 =f1 + 0 + 0 , 0 也是斐波那契数
B 看懂题意了应该很好做,虽然我没看明白,, 方法:
分别枚举每个圆,共四个,然后看他是否与另外个环是否相交, 圆心距离 =abs (r1 - r2) 内切 ,圆心距离 =abs (r1 + r2) 外切
C 很好的数学题,推公式,注意 等比数列的公比 = 1 的情况 ,
#include<map> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<string> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; int main() { long long k,b,n,t; while(cin>>k>>b>>n>>t) { if(k==1) { int dd=ceil((n*b*1.0-t+1)/b); if(dd<0) cout<<0<<endl; else cout<<dd<<endl; continue; } //cout<<(t*1.0*(k-1)+b)/(k-1.0+b)<<endl; long long limit=(long long)floor((t*1.0*(k-1)+b)/(k-1.0+b)); int ans=0; long long mul=1; // cout<<limit<<endl; //for(int i=0;i<n;i++) mul*=k; for(ans=n;mul<=limit;ans--) mul*=k; cout<<max(ans+1,0)<<endl; } return 0; } /* 126480 295416 829274 421896 829273 */
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=100100; const int INF=100000000; int n,k; char s1[maxn],s2[maxn]; int dp[2][maxn]; struct Node { int pos,t,side; Node(){} Node(int a,int b,int c) { pos=a,t=b,side=c; } }q[2*maxn]; bool find1; void bfs() { int head=0,rear=0; Node cur,next; cur.pos=0,cur.t=0,cur.side=0; q[rear++]=cur; dp[0][0]=0; while(head<rear) { next=q[head++]; if(next.side==0) { if(next.pos==n-1) { find1=1;break; } if(s1[next.pos+1]!='X'&&next.pos+1 >= next.t+1&&dp[0][next.pos+1] > next.t+1) { dp[0][next.pos+1] = next.t+1; q[rear++]=Node(next.pos+1,next.t+1,0); } if(s1[next.pos-1]!='X'&&next.pos-1 >= next.t+1&&dp[0][next.pos-1] > next.t+1) { dp[0][next.pos-1] = next.t+1; q[rear++]=Node(next.pos-1,next.t+1,0); } if(next.pos+k>=n ) { find1=1;break; } if(s2[next.pos+k]!='X'&&next.pos+k >= next.t+1 && dp[1][next.pos+k] > next.t+1) { dp[1][next.pos+k] = next.t+1; q[rear++]=Node(next.pos+k,next.t+1,1); } } else { if(next.pos==n-1) { find1=1;break; } if(s2[next.pos+1]!='X' && next.pos+1 >= next.t+1 &&dp[1][next.pos+1] > next.t+1) { dp[1][next.pos+1] = next.t+1; q[rear++]=Node(next.pos+1,next.t+1,1); } if(s2[next.pos-1]!='X' && next.pos-1 >= next.t+1 && dp[1][next.pos-1] > next.t+1 ) { dp[1][next.pos-1] = next.t+1; q[rear++]=Node(next.pos-1,next.t+1,1); } if(next.pos+k>=n ) { find1=1;break; } if(s1[next.pos+k]!='X' && next.pos+k >= next.t+1 &&dp[0][next.pos+k] > next.t+1) { dp[0][next.pos+k] = next.t+1; q[rear++]=Node(next.pos+k,next.t+1,0); } } } } int main() { while(scanf("%d%d",&n,&k)==2) { scanf("%s%s",s1,s2); for(int i=0;i<=n;i++) dp[0][i]=dp[1][i]=INF; find1=0; bfs(); puts(find1?"YES":"NO"); } return 0; }