标签:mission ubi multi icpc reg exist put others dinic
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 6778 Accepted Submission(s): 713
#include<bits/stdc++.h> using namespace std; const int MAXN = 100010; int n,k; int Paiming[MAXN+1],tmp[MAXN+1]; int flag; bool comp_sa(int i, int j) { if(Paiming[i] != Paiming[j]) return Paiming[i] < Paiming[j]; else{ int ri = i+k <= n? Paiming[i+k] : -1; int rj = j+k <= n? Paiming[j+k] : -1; return ri < rj; } } void calc_sa(string &S, int *sa) { n = S.size(); for(int i = 0; i <= n; i++) { sa[i] = i; Paiming[i] = i < n ? S[i] : -1; } for( k =1; k <= n; k *= 2) { sort(sa,sa+n+1,comp_sa); tmp[sa[0]] = 0; for(int i = 1; i <= n; i++) { tmp[sa[i]] = tmp[sa[i-1]] + (comp_sa(sa[i-1],sa[i]) ? 1: 0); } for(int i = 0; i <= n; i++) { Paiming[i] = tmp[i]; } } } int SuffixArrayMatch(string &S, int *sa, string T) { int lhs = 0, rhs = S.size(); while(rhs - lhs > 1) { int mid = (lhs + rhs)>>1; if(S.compare(sa[mid],T.size(),T) < 0) lhs = mid; else rhs=mid; } return S.compare(sa[rhs],T.size(),T) == 0; } int main() { int t; ios::sync_with_stdio(false); cin>>t; string s[100010],longs; while(t--){ int n,l=-1,p=-1,i; cin>>n; memset(Paiming,0,sizeof Paiming); memset(tmp,0,sizeof tmp); for(i=0;i<n;i++){ cin>>s[i]; int len=s[i].size(); if(len>l){ l=len; longs=s[i]; p=i; } } if(n==1){ cout<<longs<<endl; continue; } int *sa = new int[longs.size()+1]; calc_sa(longs,sa); for(i=0;i<n;i++){ if(p==i)continue; if(!SuffixArrayMatch(longs,sa,s[i])) break; } //delete [] sa; sa = NULL; if(i>=n){ cout<<longs<<endl; }else { cout<<"No"<<endl; } } }
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> using namespace std; int main() { char m[12][10]={ "rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep", "monkey", "rooster", "dog" , "pig" }; int t,s; scanf("%d",&t); while(t--){ char p[10],q[10]; scanf("%s%s",&p,&q); if(strcmp(p,q)==0){ puts("12"); }else { int i,pp,qq; for(i=0;i<12;i++){ if(strcmp(m[i],p)==0){ pp=i; } if(strcmp(m[i],q)==0){ qq=i; } } s=(pp-qq); if(s>0){ s=s-12; } printf("%d\n",-s); } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 2333 #define MAXM 2333333 struct Edge { int v,next; ll cap; } edge[MAXM]; int head[MAXN],pre[MAXN],cur[MAXN],level[MAXN],gap[MAXN],NV,NE,n,m,vs,vt; void ADD(int u,int v,ll cap,ll cc=0) { edge[NE].v=v; edge[NE].cap=cap; edge[NE].next=head[u]; head[u]=NE++; edge[NE].v=u; edge[NE].cap=cc; edge[NE].next=head[v]; head[v]=NE++; } ll SAP(int vs,int vt) { memset(pre,-1,sizeof(pre)); memset(level,0,sizeof(level)); memset(gap,0,sizeof(gap)); for(int i=0; i<=NV; i++)cur[i]=head[i]; int u=pre[vs]=vs; ll aug=-1,maxflow=0; gap[0]=NV; while(level[vs]<NV) { loop: for(int &i=cur[u]; i!=-1; i=edge[i].next) { int v=edge[i].v; if(edge[i].cap&&level[u]==level[v]+1) { aug==-1?aug=edge[i].cap:aug=min(aug,edge[i].cap); pre[v]=u; u=v; if(v==vt) { maxflow+=aug; for(u=pre[u]; v!=vs; v=u,u=pre[u]) { edge[cur[u]].cap-=aug; edge[cur[u]^1].cap+=aug; } aug=-1; } goto loop; } } int minlevel=NV; for(int i=head[u]; i!=-1; i=edge[i].next) { int v=edge[i].v; if(edge[i].cap&&minlevel>level[v]) { cur[u]=i; minlevel=level[v]; } } if(--gap[level[u]]==0)break; level[u]=minlevel+1; gap[level[u]]++; u=pre[u]; } return maxflow; } int main() { int T,u,v,w; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); scanf("%d%d",&vs,&vt); NV=n,NE=0; memset(head,-1,sizeof(head)); for(int i=1; i<=m; i++) { scanf("%d%d%d",&u,&v,&w); ADD(u,v,(ll)w*MAXM+1); } ll ans=SAP(vs,vt); printf("%d\n",ans%MAXM); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; bool la(LL x) { LL l=1,r=1e6+5; while(l<=r) { LL mi=(l+r)/2; LL y=mi-1; if(mi*mi+y*y+mi*y==x) return 1; else if(mi*mi+y*y+mi*y<x) l=mi+1; else r=mi-1; } return 0; } int main() { int T; scanf("%d",&T); while(T--) { LL n; scanf("%lld",&n); printf("%s\n",la(n)?"YES":"NO"); } return 0; }
2017 ACM/ICPC Asia Regional Qingdao Online
标签:mission ubi multi icpc reg exist put others dinic
原文地址:http://www.cnblogs.com/BobHuang/p/7541317.html