ACM-ICPC 2018 南京网络赛
A
1 /*Huyyt*/ 2 #include<bits/stdc++.h> 3 using namespace std; 4 typedef long long ll; 5 const int mod = 998244353; 6 const int maxn = 1e3 + 5; 7 int main() 8 { 9 int T; 10 cin >> T; 11 while(T--) 12 { 13 ll x; 14 scanf("%lld",&x); 15 printf("%lld\n",x-1); 16 } 17 return 0; 18 }
B
#include<bits/stdc++.h> #define lc(x) (2*x) #define rc(x) (2*x+1) #define fi first #define se second using namespace std; typedef long long ll; const ll mod = 998244353; const int maxn = 1e5+5; const int maxm = 1e2+5; int n,m,k; vector<int> v[maxm]; int lit[maxn]; int near[maxm]; int main(){ int t; scanf("%d",&t); for(int quq=1;quq<=t;quq++){ scanf("%d%d%d",&n,&m,&k); int i,j,a,b; for(i=1;i<=m;i++)v[i].clear(); for(i=1;i<=k;i++){ scanf("%d%d",&a,&b); v[b].push_back(a); } ll ans=0; memset(lit,0,sizeof(lit)); for(i=1;i<=m;i++){ memset(near,0,sizeof(near)); for(j=1;j<=n;j++){ lit[j]++; } for(j=0;j<v[i].size();j++)lit[v[i][j]]=0; for(j=1;j<=n;j++){ b = near[0]; for(a=1;a<=lit[j];a++){ ans+=(j-b); b = max(b,near[a]); } near[lit[j]]=j; } } printf("Case #%d: %lld\n",quq,ans); } }
C
1 /*Huyyt*/ 2 #include<bits/stdc++.h> 3 #define mem(a,b) memset(a,b,sizeof(a)) 4 using namespace std; 5 typedef long long ll; 6 const int mod = 998244353; 7 const int maxn = 2e4 + 5; 8 int n, m; 9 int num[maxn]; 10 int ren[205][20]; 11 int sum[205]; 12 int ans[205]; 13 int cur, biggestnum; 14 int biggestman; 15 int numcur; 16 bool flag = true; 17 void get_ans() 18 { 19 for (int i = 1; i <= n; i++) 20 { 21 for (int j = 1; j <= 13; j++) 22 { 23 ans[i] += ren[i][j] * j; 24 } 25 } 26 return ; 27 } 28 int get_min(int x) 29 { 30 for (int i = 3; i <= 13; i++) 31 { 32 if (ren[x][i]) 33 { 34 return i; 35 } 36 } 37 if (ren[x][1]) 38 { 39 return 1; 40 } 41 if (ren[x][2]) 42 { 43 return 2; 44 } 45 } 46 int get_next(int x) 47 { 48 if (x == 2) 49 { 50 return -1; 51 } 52 if (x >= 3 && x <= 12) 53 { 54 return (x + 1); 55 } 56 if (x == 1) 57 { 58 return 2; 59 } 60 if (x == 13) 61 { 62 return 1; 63 } 64 } 65 int change_man(int x) 66 { 67 if (x > n) 68 { 69 return 1; 70 } 71 return x; 72 } 73 void chouka(int x) 74 { 75 for (int i = x; i <= n && cur <= m; i++) 76 { 77 ren[i][num[cur++]]++; 78 sum[i]++; 79 } 80 for (int i = 1; i < x && cur <= m; i++) 81 { 82 ren[i][num[cur++]]++; 83 sum[i]++; 84 } 85 } 86 void go(int mannow) 87 { 88 if (!flag) 89 { 90 return ; 91 } 92 mannow = change_man(mannow); 93 if (mannow == biggestman) 94 { 95 chouka(biggestman); 96 return ; 97 } 98 if (biggestnum == 2) 99 { 100 chouka(biggestman); 101 return ; 102 } 103 int aim = get_next(biggestnum); 104 if (aim == -1) 105 { 106 chouka(biggestman); 107 return ; 108 } 109 if (ren[mannow][aim]) 110 { 111 ren[mannow][aim]--; 112 sum[mannow]--; 113 if (sum[mannow] == 0) 114 { 115 flag = false; 116 get_ans(); 117 return ; 118 } 119 biggestman = mannow, biggestnum = aim; 120 go(mannow + 1); 121 } 122 else 123 { 124 if (ren[mannow][2]) 125 { 126 ren[mannow][2]--; 127 sum[mannow]--; 128 if (sum[mannow] == 0) 129 { 130 flag = false; 131 get_ans(); 132 return ; 133 } 134 biggestman = mannow, biggestnum = 2; 135 go(mannow + 1); 136 } 137 else 138 { 139 go(mannow + 1); 140 } 141 } 142 } 143 int main() 144 { 145 int T; 146 cin >> T; 147 for (int cas = 1; cas <= T; cas++) 148 { 149 flag = true; 150 numcur = 1, cur = 1, biggestnum = -1; 151 mem(ren, 0), mem(ans, 0), mem(sum, 0); 152 scanf("%d %d", &n, &m); 153 for (int i = 1; i <= m; i++) 154 { 155 scanf("%d", &num[i]); 156 } 157 for (int i = 1; i <= n; i++) 158 { 159 int add = 0; 160 for (; cur <= m && add <= 4;) 161 { 162 //cout<<i<<" "<<num[cur]<<endl; 163 ren[i][num[cur++]]++; 164 sum[i]++; 165 add++; 166 } 167 } 168 biggestman = 1; 169 while (flag) 170 { 171 if (sum[biggestman] == 0) 172 { 173 get_ans(); 174 flag = false; 175 continue; 176 } 177 biggestnum = get_min(biggestman); 178 ren[biggestman][biggestnum]--; 179 sum[biggestman]--; 180 if (sum[biggestman] == 0) 181 { 182 get_ans(); 183 flag = false; 184 continue; 185 } 186 go(biggestman + 1); 187 } 188 printf("Case #%d:\n", cas); 189 for (int i = 1; i <= n; i++) 190 { 191 if (ans[i] == 0) 192 { 193 printf("Winner\n"); 194 } 195 else 196 { 197 printf("%d\n", ans[i]); 198 } 199 } 200 } 201 return 0; 202 }
D
1 /* 2 Author: LargeDumpling 3 Email: LargeDumpling@qq.com 4 Edit History: 5 2018-09-01 File created. 6 */ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<cstdlib> 11 #include<cstring> 12 #include<cmath> 13 #include<algorithm> 14 using namespace std; 15 const int MAXN=1050; 16 const double eps=1e-10; 17 int dcmp(const double &x) { if(fabs(x)<eps) return 0; return x<0?-1:1; } 18 typedef struct Poi Vec; 19 struct Poi 20 { 21 double x,y; 22 Poi(const double &a=0,const double &b=0):x(a),y(b) { } 23 Poi operator+(const Poi &P)const { return Poi(x+P.x,y+P.y); } 24 Poi operator-(const Poi &P)const { return Poi(x-P.x,y-P.y); } 25 Poi operator*(const double &P)const { return Poi(x*P,y*P); } 26 Poi operator/(const double &P)const { return Poi(x/P,y/P); } 27 bool operator<(const Poi &P)const { return !dcmp(x-P.x)?dcmp(y-P.y)<=0:dcmp(x-P.x)<=0; } 28 }PP[MAXN],NP[MAXN<<1],IP[MAXN]; 29 struct Line 30 { 31 Poi Ps; Vec Dir; 32 double ang; 33 Line(const Poi &ps=Poi(),const Vec &dir=Vec()):Ps(ps),Dir(dir) { ang=atan2(Dir.y,Dir.x); } 34 bool operator<(const Line &L1)const { return ang<L1.ang; } 35 }lines[MAXN],q[MAXN]; 36 double dOt(const Vec &V1,const Vec &V2) { return V1.x*V2.x+V1.y*V2.y; } 37 double cRoss(const Vec &V1,const Vec &V2) { return V1.x*V2.y-V1.y*V2.x; } 38 double lEnth(const Vec V) { return sqrt(dOt(V,V)); } 39 Vec Normal(const Vec &V) { return Vec(-V.y,V.x); } 40 Poi iNtersect(const Poi &P1,const Vec &V1,const Poi &P2,const Vec &V2) 41 { return P1+V1*(cRoss(V2,P1-P2)/cRoss(V1,V2)); } 42 Poi iNtersect(const Line &L1,const Line &L2) 43 { return iNtersect(L1.Ps,L1.Dir,L2.Ps,L2.Dir); } 44 int HPI(Line *L,int N,Poi *Pol) 45 { 46 int l,r,m=0; 47 sort(L,L+N);//按极角排序 48 q[l=r=0]=L[0]; 49 for(int i=1;i<N;i++) 50 { 51 while(l<r&&dcmp(cRoss(L[i].Dir,IP[r-1]-L[i].Ps))<=0) r--; //新加入的直线可能是尾部的一些交点失效 52 while(l<r&&dcmp(cRoss(L[i].Dir,IP[l]-L[i].Ps))<=0) l++; //首部 53 q[++r]=L[i]; //加入 54 if(!dcmp(cRoss(q[r].Dir,q[r-1].Dir))) 55 { //对于平行直线要取靠左的 56 r--; 57 if(dcmp(cRoss(q[r+1].Dir,q[r].Ps-q[r+1].Ps))<0) q[r]=q[r+1]; 58 } 59 if(l<r) IP[r-1]=iNtersect(q[r-1],q[r]); //如果队列中有至少两条线,则取交点 60 } 61 while(l<r&&dcmp(cRoss(q[l].Dir,IP[r-1]-q[l].Ps))<=0) r--; //后面一些交点可能实际上是无用的 62 if(r-l<2) return 0; //如果只有不到两条线,则失败了 63 IP[r]=iNtersect(q[l],q[r]); //将最后一条线和第一条线交起来 64 for(int i=l;i<=r;i++) Pol[m++]=IP[i]; 65 Pol[m]=Pol[0]; 66 return m; 67 } 68 double area(const Poi &P1,const Poi &P2,const Poi &P3) 69 { 70 return fabs(cRoss(P3-P1,P2-P1)); 71 } 72 double calc(int n,Poi *P) 73 { 74 int l,r,mid1,mid2,tem; 75 double ans=0; 76 for(int i=0;i<=n;i++) 77 P[i+n]=P[i]; 78 for(int i=0;i<n;i++) 79 for(int j=i+1;j<n;j++) 80 { 81 l=i; r=j; 82 while(l<r-1) 83 { 84 tem=(r-l+1)/3; 85 mid1=l+tem; 86 mid2=r-tem; 87 if(area(P[i],P[j],P[mid1])<area(P[i],P[j],P[mid2])) l=mid1; 88 else r=mid2; 89 } 90 ans=max(ans,max(area(P[i],P[j],P[l]),area(P[i],P[j],P[r]))); 91 l=j; r=i+n; 92 while(l<r-1) 93 { 94 tem=(r-l+1)/3; 95 mid1=l+tem; 96 mid2=r-tem; 97 if(area(P[i],P[j],P[mid1])<area(P[i],P[j],P[mid2])) l=mid1; 98 else r=mid2; 99 } 100 ans=max(ans,max(area(P[j],P[i+n],P[l]),area(P[j],P[i+n],P[r]))); 101 } 102 return ans; 103 } 104 int main() 105 { 106 int T_T,n,m; 107 double r; 108 Vec Nv; 109 scanf("%d",&T_T); 110 while(T_T--) 111 { 112 scanf("%d%lf",&n,&r); 113 for(int i=0;i<n;i++) scanf("%lf%lf",&PP[n-i-1].x,&PP[n-i-1].y); 114 PP[n]=PP[0]; 115 for(int i=0;i<n;i++) 116 { 117 Nv=Normal(PP[i+1]-PP[i]); 118 Nv=Nv/lEnth(Nv); 119 lines[i]=Line(PP[i]+Nv*r,PP[i+1]-PP[i]); 120 } 121 m=HPI(lines,n,NP); 122 printf("%lf\n",calc(m,NP)); 123 } 124 fclose(stdin); 125 fclose(stdout); 126 return 0; 127 }
E
1 /* 2 Author: LargeDumpling 3 Email: LargeDumpling@qq.com 4 Edit History: 5 2018-09-01 File created. 6 */ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<cstdlib> 11 #include<cstring> 12 #include<cmath> 13 #include<queue> 14 #include<algorithm> 15 using namespace std; 16 const int MAXN=25; 17 struct jz 18 { 19 int u,S,cnt; 20 jz(const int &U=0,const int &SS=0,const int &C=0):u(U),S(SS),cnt(C) { } 21 }; 22 bool aa; 23 int n,pre[MAXN]; 24 long long a[MAXN],b[MAXN],f[1100000],ans=0; 25 bool exist[1100000],vis[1100000]; 26 bool bb; 27 void SPFA() 28 { 29 int S=0; 30 long long cnt=0; 31 queue<jz> q; 32 f[0]=0; 33 for(int i=0;i<n;i++) if((pre[i]&S)==pre[i] 34 &&(!vis[S|(1<<i)]||f[S|(1<<i)]<f[S]+a[i]*(cnt+1LL)+b[i])) 35 { 36 f[S|(1<<i)]=f[S]+a[i]*(cnt+1LL)+b[i]; 37 vis[S|(1<<i)]=true; 38 q.push(jz(i,S|(1<<i),cnt+1)); 39 exist[S|(1<<i)]=true; 40 } 41 while(q.size()) 42 { 43 S=q.front().S; 44 cnt=q.front().cnt; 45 q.pop(); 46 exist[S]=false; 47 for(int i=0;i<n;i++) if((!((S>>i)&1))&&((pre[i]&S)==pre[i]) 48 &&(!vis[S|(1<<i)]||f[S|(1<<i)]<f[S]+a[i]*(cnt+1LL)+b[i])) 49 { 50 f[S|(1<<i)]=f[S]+a[i]*(cnt+1LL)+b[i]; 51 vis[S|(1<<i)]=true; 52 ans=max(ans,f[S|(1<<i)]); 53 if(!exist[S|(1<<i)]) 54 { 55 exist[S|(1<<i)]=true; 56 q.push(jz(i,S|(1<<i),cnt+1)); 57 } 58 } 59 } 60 return; 61 } 62 int main() 63 { 64 int pn,x; 65 scanf("%d",&n); 66 for(int i=0;i<n;i++) 67 { 68 scanf("%lld%lld%d",&a[i],&b[i],&pn); 69 while(pn--) 70 { 71 scanf("%d",&x); x--; 72 pre[i]|=(1<<x); 73 } 74 } 75 SPFA(); 76 printf("%lld\n",ans); 77 fclose(stdin); 78 fclose(stdout); 79 return 0; 80 }
F
G
1 /* 2 Author: LargeDumpling 3 Email: LargeDumpling@qq.com 4 Edit History: 5 2018-09-01 File created. 6 */ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<cstdlib> 11 #include<cstring> 12 #include<cmath> 13 #include<algorithm> 14 using namespace std; 15 const int MAXN=100050; 16 const int M=131072; 17 const int INF=2147483647; 18 int n,m; 19 int mbl[MAXN],d[M<<1]; 20 int ans[MAXN][2]; 21 void read1n(int &x) 22 { 23 char ch; 24 for(ch=getchar();ch<'0'||'9'<ch;ch=getchar()) 25 if(ch==-1) return; 26 for(x=0;'0'<=ch&&ch<='9';ch=getchar()) 27 x=(x<<1)+(x<<3)+ch-'0'; 28 return; 29 } 30 void build() 31 { 32 for(int i=1;i<=n;i++) 33 d[i+M]=mbl[i]; 34 for(int i=M-1;i;i--) 35 d[i]=min(d[i<<1],d[i<<1|1]); 36 return; 37 } 38 void del(int x) 39 { 40 mbl[x]=d[x+M]=INF; 41 for(int i=(x+M)>>1;i;i>>=1) 42 d[i]=min(d[i<<1],d[i<<1|1]); 43 return; 44 } 45 int query(int L,int R) 46 { 47 int ans=INF; 48 for(L=L+M-1,R=R+M+1;L<R-1;L>>=1,R>>=1) 49 { 50 if(!(L&1)) ans=min(ans,d[L^1]); 51 if(R&1) ans=min(ans,d[R^1]); 52 } 53 return ans; 54 } 55 void calc() 56 { 57 int nex,cnt,now,l,mid,r,left=0; 58 ans[0][0]=ans[0][1]=0; 59 build(); 60 cnt=0; 61 for(int i=1;i<MAXN;i++) 62 { 63 if(cnt==n) 64 { 65 ans[i][0]=ans[i-1][0]; 66 ans[i][1]=ans[i-1][1]; 67 continue; 68 } 69 left+=m; 70 now=1; 71 while(true) 72 { 73 if(mbl[now]<=left) nex=now; 74 else if(left<query(now,n)) nex=n+1; 75 else 76 { 77 l=now; r=n; 78 while(l<r-1) 79 { 80 mid=(l+r)>>1; 81 if(query(now,mid)<=left) r=mid; 82 else l=mid; 83 } 84 nex=r; 85 } 86 if(nex==n+1) break; 87 left-=mbl[nex]; 88 cnt++; 89 del(nex); 90 now=nex; 91 } 92 ans[i][0]=cnt; 93 ans[i][1]=left; 94 } 95 } 96 int main() 97 { 98 int Q,x; 99 read1n(n); read1n(m); 100 for(int i=1;i<=n;i++) 101 scanf("%d",&mbl[i]); 102 calc(); 103 read1n(Q); 104 while(Q--) 105 { 106 read1n(x); 107 printf("%d %d\n",ans[x][0],ans[x][1]); 108 } 109 fclose(stdin); 110 fclose(stdout); 111 return 0; 112 }
H
I
1 /* 2 Author: LargeDumpling 3 Email: LargeDumpling@qq.com 4 Edit History: 5 2018-09-01 File created. 6 */ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<cstdlib> 11 #include<cstring> 12 #include<cmath> 13 #include<algorithm> 14 using namespace std; 15 const int MAXN=2000050; 16 const int MAXC=10; 17 const long long mod=1000000007LL; 18 char str[MAXN]; 19 int ch[MAXN][MAXC],len[MAXN],fail[MAXN],last,sz; 20 long long num[MAXN],ans,p[MAXN]; 21 int getfail(char T[],int x,int i) 22 { 23 while(T[i-len[x]-1]!=T[i]) x=fail[x]; 24 return x; 25 } 26 void init() 27 { 28 memset(ch[0],last=0,sizeof(ch[0]));//last为当前的最长后缀回文 29 memset(ch[1],0,sizeof(ch[1])); 30 len[0]=0; len[1]=-1; 31 fail[0]=1; 32 num[0]=num[1]=0; 33 sz=1; 34 ans=0; 35 return; 36 } 37 void insert(char T[]) 38 { 39 int lenth=strlen(T),cur=0; 40 for(int i=0;i<lenth;i++) 41 { 42 cur=getfail(T,last,i); 43 if(!ch[cur][T[i]-'0']) 44 { 45 fail[++sz]=ch[ getfail(T,fail[cur],i) ][T[i]-'0']; 46 ch[cur][T[i]-'0']=sz; 47 memset(ch[sz],0,sizeof(ch[sz])); 48 len[sz]=len[cur]+2; 49 if(cur==1) num[sz]=T[i]-'0'; 50 else num[sz]=(num[cur]*10LL%mod+p[len[cur]+1]*(T[i]-'0')%mod+(T[i]-'0'))%mod; 51 ans=(ans+num[sz])%mod; 52 } 53 last=ch[cur][T[i]-'0']; 54 } 55 return; 56 } 57 void pre_calc() 58 { 59 p[0]=1; 60 p[1]=10LL; 61 for(int i=2;i<MAXN;i++) p[i]=p[i-1]*p[1]%mod; 62 return; 63 } 64 int main() 65 { 66 init(); 67 pre_calc(); 68 scanf("%s",str); 69 insert(str); 70 printf("%lld\n",ans); 71 fclose(stdin); 72 fclose(stdout); 73 return 0; 74 }
J
1 #include<bits/stdc++.h> 2 #define lc(x) (2*x) 3 #define rc(x) (2*x+1) 4 #define fi first 5 #define se second 6 using namespace std; 7 typedef long long ll; 8 9 const ll mod = 998244353; 10 const int maxn = 2e7+5; 11 const int maxm = 1e4; 12 int num[maxn],is[maxn]; 13 int n; 14 15 void yuchuli(){ 16 int i,j,a,b; 17 for(i=2;;i++){ 18 if(i*i>=maxn)break; 19 a=i*i; 20 for(j=a;j<maxn;j+=a)is[j]=1; 21 } 22 for(i=1;i<maxn;i++)num[i]=num[i-1]+1-is[i]; 23 } 24 25 int main(){ 26 int t; 27 yuchuli(); 28 scanf("%d",&t); 29 while(t--){ 30 scanf("%d",&n); 31 int i,j,a,b; 32 ll ans=0; 33 for(i=1;i<=maxm;i++){ 34 if(is[i])continue; 35 j=n/i; 36 ans += num[j]; 37 if(j>maxm)ans+=num[j]-num[maxm]; 38 } 39 printf("%lld\n",ans); 40 } 41 }
K
L
1 /* 2 Author: LargeDumpling 3 Email: LargeDumpling@qq.com 4 Edit History: 5 2018-09-01 File created. 6 */ 7 8 #include<iostream> 9 #include<cstdio> 10 #include<cstdlib> 11 #include<cstring> 12 #include<cmath> 13 #include<queue> 14 #include<algorithm> 15 using namespace std; 16 const int MAXN=100050; 17 const int MAXM=200050; 18 struct jz 19 { 20 int u; 21 long long dis; 22 jz(const int &U=0,const long long &D=0):u(U),dis(D) { } 23 bool operator<(const jz &X)const { return dis==X.dis?u>X.u:dis>X.dis; } 24 }; 25 bool aaa; 26 int T_T,n,m,k; 27 int fir[MAXN*15],eNd[MAXM*25],nxt[MAXM*25],ed=0; 28 bool vis[MAXN*15]; 29 long long len[MAXM*25],dis[MAXN*15],ans; 30 bool bbb; 31 void addedge(int u,int v,int w) 32 { 33 eNd[++ed]=v; 34 nxt[ed]=fir[u]; 35 len[ed]=w; 36 fir[u]=ed; 37 return; 38 } 39 void read1n(int &x) 40 { 41 char ch=getchar(); 42 while(ch<'0'||'9'<ch) ch=getchar(); 43 for(x=0;'0'<=ch&&ch<='9';ch=getchar()) 44 x=(x<<1)+(x<<3)+ch-'0'; 45 return; 46 } 47 void init() 48 { 49 memset(fir,ed=0,sizeof(fir)); 50 memset(dis,-1,sizeof(dis)); 51 memset(vis,false,sizeof(vis)); 52 return; 53 } 54 void Hijkstra() 55 { 56 int u; 57 priority_queue<jz> q; 58 dis[1]=0; 59 q.push(jz(1,0)); 60 while(q.size()) 61 { 62 while(q.size()&&(vis[q.top().u]||dis[q.top().u]!=q.top().dis)) 63 q.pop(); 64 if(!q.size()) break; 65 u=q.top().u; q.pop(); 66 vis[u]=true; 67 for(int i=fir[u];i;i=nxt[i]) if(dis[eNd[i]]==-1||dis[u]+len[i]<dis[eNd[i]]) 68 { 69 dis[eNd[i]]=dis[u]+len[i]; 70 q.push(jz(eNd[i],dis[eNd[i]])); 71 } 72 } 73 return; 74 } 75 int Rand() 76 { 77 return (rand()<<15)+rand(); 78 } 79 int main() 80 { 81 int u,v,w; 82 read1n(T_T); 83 //T_T=5; 84 while(T_T--) 85 { 86 init(); 87 read1n(n); 88 //n=100000; 89 read1n(m); 90 //m=200000; 91 read1n(k); 92 //k=10; 93 for(int i=1;i<=m;i++) 94 { 95 read1n(u); 96 //u=Rand()%n+1; 97 read1n(v); 98 //v=Rand()%n+1; 99 read1n(w); 100 //w=1000000000; 101 for(int j=0;j<=k;j++) 102 { 103 addedge(u+j*n,v+j*n,w); 104 if(j<k) addedge(u+j*n,v+(j+1)*n,0); 105 } 106 } 107 Hijkstra(); 108 ans=dis[n]; 109 for(int i=1;i<=k;i++) 110 ans=min(ans,dis[(i+1)*n]); 111 printf("%lld\n",ans); 112 } 113 fclose(stdin); 114 fclose(stdout); 115 return 0; 116 }