Codeforces Round #196 (Div. 2)
涨了那么一点 。。
A纯水 把CF都交挂了。。
B 扩展与x相同 或与y相同
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 int gcd(int a,int b) 8 { 9 return b==0? a:gcd(b,a%b); 10 } 11 int main() 12 { 13 int i,j,a,b,c,d; 14 cin>>a>>b>>c>>d; 15 int x =a*c/gcd(a,c); 16 int y = b*d/gcd(b,d); 17 int x1 = b*(x/a); 18 int y1 = d*(x/c); 19 int x2 = a*(y/b); 20 int y2 = c*(y/d); 21 if(x1>=y1) 22 { 23 24 y1 = x1-y1; 25 int o = gcd(x1,y1); 26 printf("%d/%d\n",y1/o,x1/o); 27 } 28 else 29 { 30 y2 = x2-y2; 31 int o = gcd(x2,y2); 32 printf("%d/%d\n",y2/o,x2/o); 33 } 34 return 0; 35 }
C 题 搞笑。。我把2倍看成了平方 然后WA到结束。。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 #define LL __int64 8 #define mod 1000000009 9 LL poww(LL a,LL n) 10 { 11 LL t; 12 if(n==0) return 1%mod; 13 if(n==1) return a%mod; 14 t=poww(a,n/2); 15 t=t*t%mod; 16 if((n&1)==1) t=t*a%mod; 17 return t; 18 } 19 int main() 20 { 21 LL i,k,n,m; 22 cin>>n>>m>>k; 23 LL o = n-m; 24 if((o+1)*(k-1)>=m) 25 { 26 printf("%I64d\n",m); 27 } 28 else 29 { 30 LL s = o*(k-1); 31 LL y = (m-s)/k; 32 LL ans = (k*poww(2,y+1)%mod-2*k%mod)%mod; 33 ans = (ans+(m-s-y*k)%mod+s)%mod; 34 if(ans<0) 35 ans+=mod; 36 printf("%I64d\n",ans); 37 } 38 return 0; 39 }
D题 找m点里面最长的两个点 再以这两个点进行两遍dfs 如果某点离这个两个点的距离都小于d 那么其它的也小于
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 #define N 100010 8 struct node 9 { 10 int u,v,next; 11 }ed[N<<1]; 12 int t,head[N]; 13 void init() 14 { 15 t =0; 16 memset(head,-1,sizeof(head)); 17 } 18 void add(int u,int v) 19 { 20 ed[t].u = u; 21 ed[t].v = v; 22 ed[t].next = head[u]; 23 head[u] = t++; 24 } 25 void dfs(int u,int pre,int dd,int o[]) 26 { 27 o[u] = dd; 28 for(int i = head[u] ; i != -1; i = ed[i].next) 29 { 30 int v = ed[i].v; 31 if(v==pre) 32 continue; 33 dfs(v,u,dd+1,o); 34 } 35 } 36 int s1[N],s2[N],s3[N],f[N]; 37 int main() 38 { 39 int i,n,m,d,k; 40 init(); 41 cin>>n>>m>>d; 42 for(i =1; i <= m ; i++) 43 scanf("%d",&f[i]); 44 for(i = 1; i < n ;i++) 45 { 46 int u,v; 47 scanf("%d%d",&u,&v); 48 add(u,v); 49 add(v,u); 50 } 51 dfs(f[1],-1,0,s1); 52 k = f[1]; 53 for(i = 2; i <= m ; i++) 54 { 55 if(s1[k]<s1[f[i]]) 56 k = f[i]; 57 } 58 dfs(k,-1,0,s2); 59 k = f[1]; 60 for(i = 2; i <= m ; i++) 61 if(s2[k]<s2[f[i]]) 62 k = f[i]; 63 dfs(k,-1,0,s3); 64 int ans = 0; 65 for(i = 1; i <= n ; i++) 66 if(s2[i]<=d&&s3[i]<=d) 67 ans++; 68 printf("%d\n",ans); 69 return 0; 70 71 }