A. Who is better?
code :
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll fib[105],m[20],r[20],k; ll gcd(ll a,ll b) { if (b==0) return a; else return gcd(b,a%b); } ll extend_gcd(ll a,ll b,ll &x,ll &y) { if (b==0) { x=1; y=0; return a; } ll u=extend_gcd(b,a%b,x,y); ll temp=x; x=y; y=temp-(a/b)*y; return u; } ll solve() { ll M=m[1],R=r[1],x,y; for (ll i=2;i<=k;i++) { ll d=gcd(M,m[i]); ll c=r[i]-R; if (c%d!=0) return -1; extend_gcd(M/d,m[i]/d,x,y); x=(c/d*x)%(m[i]/d); R=R+x*M; M=M/d*m[i]; R%=M; } if (R<0) R+=M; return R; } int main() { ll i,m0,a0,x,n; bool flag; fib[1]=1; fib[2]=1; for (i=3;i<=100;i++) fib[i]=fib[i-1]+fib[i-2]; // cout<<fib[100]<<endl; cin>>k; for (i=1;i<=k;i++) { cin>>m[i]>>r[i]; n=solve(); // cout<<x<<endl; } if (n==-1) { cout<<"Tankernb!"<<endl; return 0; } // cout<<n<<endl; for (i=3;i<=100;i++) if (fib[i]==n) { cout<<"Lbnb!"<<endl; return 0; } cout<<"Zgxnb!"<<endl; return 0; }B. so easy
code:
#include <bits/stdc++.h> using namespace std; const int N=1e6+1000; int n,q,x[N],xx[N],fat[N],op[N],b[N]={0}; int father(int p) { if (fat[p]==p) return p; else return fat[p]=father(fat[p]); } void combine(int p1,int p2) { int f1,f2; f1=father(p1); f2=father(p2); if (f1!=f2) fat[f1]=f2; } int main() { int i,k,g,m; scanf("%d%d",&n,&q); for (i=1;i<=q;i++) { scanf("%d%d",&op[i],&x[i]); xx[i]=x[i]; } sort(xx+1,xx+q+1); m=unique(xx+1,xx+q+1)-xx; m--; // cout<<m<<endl; // for (i=1;i<=m;i++) cout<<xx[i]<<' '; // cout<<endl; for (i=1;i<=q;i++) fat[i]=i; for (i=1;i<=q;i++) { k=lower_bound(xx+1,xx+m+1,x[i])-xx; // cout<<"aaa"<<k<<endl; if (op[i]==1&&b[k]==0) { b[k]=1; if (k>1&&b[k-1]&&xx[k-1]+1==xx[k]) combine(k-1,k); if (k<m&&b[k+1]&&xx[k]+1==xx[k+1]) combine(k,k+1); } else { if (b[k]==0) printf("%d\n",x[i]);//cout<<x[i]<<endl; else { g=father(k); printf("%d\n",xx[g]+1); //cout<<xx[g]+1<<endl; } } } return 0; }
C:Buy Watermelon
code :
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; int main(){ ios::sync_with_stdio(false); int w; cin >> w; if(w%2!=1 && w>2) cout<<"YES"; else cout << "NO"; return 0; }
D. Carneginon
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; int main(){ ios::sync_with_stdio(false); string T; cin >> T; int q; cin >> q; int tlen = T.length(); while(q--){ string s; cin >> s; int len = s.length(); if(len == tlen){ if(s == T)cout << "jntm!" << endl; else cout << "friend!" << endl; } else if(len < tlen){ if(T.find(s)==-1)cout << "oh, child!" << endl; else cout << "my child!" << endl; } else if(len > tlen){ if(s.find(T)!=-1)cout << "my teacher!" << endl; else cout << "senior!" << endl; } } return 0; }
E. XKC's basketball team
#include <bits/stdc++.h> using namespace std; const int N=5e5+100; typedef struct { int l,r,maxr; } node; node tree[N*5]; int n,m; int a[N],b[N],ans[N]; void build(int left,int right,int num) { int mid=(left+right)/2; tree[num].l=left; tree[num].r=right; tree[num].maxr=-1; if (left==right) return; build(left,mid,num*2); build(mid+1,right,num*2+1); } int findmax(int k,int num) { int ans1; int left=tree[num].l,right=tree[num].r,mid=(left+right)/2; if (k<=left) return tree[num].maxr; else { ans1=findmax(k,num*2+1); if (k<=mid) ans1=max(ans1,findmax(k,num*2)); } return ans1; } void ins(int k,int j,int num) { int left=tree[num].l,right=tree[num].r,mid=(left+right)/2; if (left==right) { tree[num].maxr=max(tree[num].maxr,j); return; } if (k<=mid) ins(k,j,num*2); else ins(k,j,num*2+1); tree[num].maxr=max(tree[num*2].maxr,tree[num*2+1].maxr); } int main() { int i,p,k,t1; cin>>n>>m; for (i=1;i<=n;i++) { scanf("%d",&a[i]); b[i]=a[i]; } sort(b+1,b+n+1); p=unique(b+1,b+n+1)-b-1; // for (i=1;i<=p;i++) cout<<b[i]<<' '; cout<<endl; build(1,p,1); for (i=n;i>=1;i--) { k=lower_bound(b+1,b+p+1,a[i]+m)-b; // cout<<k<<endl; if (k>p) ans[i]=-1; else { t1=findmax(k,1); if (t1==-1) ans[i]=-1; else ans[i]=t1-i-1; } // cout<<"aaa"<<endl; k=lower_bound(b+1,b+p+1,a[i])-b; ins(k,i,1); } for (i=1;i<n;i++) printf("%d ",ans[i]); printf("-1\n"); return 0; }K. Center
code :
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1003; int a[maxn],b[maxn]; map<pair<double,double>,int> mp; ll min(ll a,ll b){return a<b?a:b;} ll max(ll a,ll b){return a>b?a:b;} int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i],&b[i]); } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) //if(i==j) mp[make_pair(double((a[i]+a[j])*1.0/2.0),double((b[i]+b[j])*1.0/2.0))]++; //else mp[make_pair(double((a[i]+a[j])*1.0/2.0),double((b[i]+b[j])*1.0/2.0))]++; map<pair<double,double>,int>::iterator it; int cnt=0,ans=n; for(it=mp.begin();it!=mp.end();it++) { //printf("\n%lf %lf %d \n",(*it).first.first,(*it).first.second,(*it).second); cnt=max(cnt,(*it).second); } cout<<max(n-cnt,0); return 0; }