Codeforces Round #382 (Div. 1), problem: (E) Chess Championship Solution in C/C++

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

#include<iostream> #include<cstdio> #include<algorithm> #define N 3010 using namespace std; int n,m,f[N][N]; struct ma{int x,y;}a[N]; bool operator<(ma p,ma q){return p.x>q.x;} void get(int k) { sort(a+k,a+n+1); int w=a[k].x; for(int i=n;i>k;i--) { if(w>1) w-=2,f[a[k].y][a[i].y]=1; else if(!w) a[i].x-=2,f[a[i].y][a[k].y]=1; else w--,a[i].x--,f[a[k].y][a[i].y]=f[a[i].y][a[k].y]=2; } a[k].x=0; } int main() { cin>>n>>m; int [...]

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

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

#include <bits/stdc++.h> using namespace std; const int N=2e3+1; int n,m,x[N*N],y[N*N]; bitset<N*2> a[N]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d",x+i,y+i); x[i]--; y[i]--; a[x[i]].set(y[i]); } for(int i=0;i<n;i++) a[i][i+n]=1; for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { if(a[j][i]) { swap(a[j],a[i]); break; } } for(int j=0;j<n;j++) { if(j!=i&&a[j][i]) a[j]^=a[i]; [...]

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

By | 2016-12-17T16:25:28+00:00 December 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:00 December 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:00 December 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); }