Codeforces Round #382 (Div. 2), problem: (E) Ostap and Tree, Accepted Solution in C/C++

By |2016-12-17T16:25:28+00:00December 17th, 2016|Categories: Uncategorized|Tags: , , , , |

#include <stdio.h> #include <string.h> #include <stdlib.h> #define M 1000000007 int add(int a, int b) { return (a + b) % M; } int mult(int a, int b) { return ((long long) a * b) % M; } #define K 20 struct edge { int [...]

Codeforces Round #382 (Div. 2), problem: (D) Taxes Solution in C/C++

By |2017-04-07T22:11:48+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<stdio.h> int isprime(int n); int main(){ int n; scanf("%d",&n); if(n%2==1){ if(isprime(n)){ printf("1"); }else{ printf("%d",3-isprime(n-2)); } }else{ printf("%d",1+(n>2)); } return 0; } int isprime(int n){ int i,j; for(i=2;i*i<=n;i++){ if(n%i==0){ return 0; } } return 1; }

Codeforces Round #382 (Div. 2), problem: (C) Tennis Championship Solution in C/C++

By |2017-04-07T22:11:48+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<stdio.h> main() { long long int n,i,j,c=0,a,b,k; scanf("%I64d",&n); a=1; b=1; k=a+b; while(k<=n) { c++; a=b; b=k; k=a+b; } printf("%I64d",c); }

Codeforces Round #382 (Div. 2), problem: (B) Urbanization Solution in C/C++

By |2017-04-07T22:11:48+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , |

#include<stdio.h> #include<stdlib.h> int cmp(const void*a,const void*b) { return *(int*)b-*(int*)a; } int w[100005]; int main() { int n,n1,n2; scanf("%d%d%d",&n,&n1,&n2); for(int i=0;i<n;i++) scanf("%d",&w[i]); qsort(w,n,sizeof(w[0]),cmp); if(n1>n2) { int t=n1; n1=n2; n2=t; } double count1=0,count2=0; for(int i=0;i<n1;i++) { count1+=1.0*w[i]; } for(int i=n1;i<n1+n2;i++) { count2+=1.0*w[i]; } printf("%.8lf\n",count1/n1+count2/n2); return 0; [...]

Codeforces Round #382 (Div. 2), problem: (A) Ostap and Grasshopper Solution in C/C++

By |2017-04-07T22:11:48+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , |

  #include<stdio.h> int b[105],d[105]; int main(){ int i,s,n,k,t; scanf("%d%d",&n,&k); char x; for(i=1;i<=n;i++){ scanf(" %c",&x); if(x=='G')s=i; if(x=='T')t=i; if(x=='#')b[i]=1; } for(i=s;i<=n;i+=k){ if(b[i]) break; d[i]=1; } for(i=s;i>=1;i-=k){ if(b[i]) break; d[i]=1; } if(d[t]) printf("YES"); else printf("NO"); }