$$2017-2018\ ACM-ICPC,\ Asia\ Daejeon\ Regional\ Contest$$

\(A.Broadcast\ Stations\)

\(B.Connect3\)

BFS+哈希判重,哈希就用一个16位的三进制数表示即可

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. using LL = int_fast64_t;
  6. struct Matrix{
  7. int mat[4][4],stp[4];
  8. LL hashval;
  9. int curcol;
  10. Matrix(){
  11. memset(mat,0,sizeof(mat));
  12. memset(stp,0,sizeof(stp));
  13. hashval = curcol = 0;
  14. }
  15. };
  16. set<int> vis;
  17. int st,edx,edy;
  18. LL powt[20];
  19. int check(const Matrix& M){
  20. for(int i = 0; i < 4; i++){
  21. for(int j = 0; j < 2; j++){
  22. if(M.mat[i][j]&&M.mat[i][j]==M.mat[i][j+1]&&M.mat[i][j]==M.mat[i][j+2]) return M.mat[i][j];
  23. if(M.mat[j][i]&&M.mat[j][i]==M.mat[j+1][i]&&M.mat[j][i]==M.mat[j+2][i]) return M.mat[j][i];
  24. }
  25. }
  26. int sx[4] = {0,1,0,1};
  27. int sy[4] = {0,0,1,1};
  28. for(int i = 0; i < 4; i++){
  29. int x = sx[i], y = sy[i];
  30. if(M.mat[x][y]&&M.mat[x][y]==M.mat[x+1][y+1]&&M.mat[x][y]==M.mat[x+2][y+2]) return M.mat[x][y];
  31. }
  32. sy[0] = 2, sy[1] = 3, sy[2] = 3, sy[3] = 2;
  33. for(int i = 0; i < 4; i++){
  34. int x = sx[i], y = sy[i];
  35. if(M.mat[x][y]&&M.mat[x][y]==M.mat[x+1][y-1]&&M.mat[x][y]==M.mat[x+2][y-2]) return M.mat[x][y];
  36. }
  37. return 0;
  38. }
  39. int bfs(){
  40. int tot = 0;
  41. queue<Matrix> que;
  42. Matrix start;
  43. start.mat[st][0] = 1;
  44. start.curcol = 1;
  45. start.hashval += powt[4*st];
  46. start.stp[st] = 1;
  47. vis.insert(start.hashval);
  48. que.push(start);
  49. while(!que.empty()){
  50. Matrix now = que.front();
  51. que.pop();
  52. int color = now.curcol ^ 3;
  53. LL hax = now.hashval;
  54. for(int i = 0; i < 4; i++){
  55. int stpos = now.stp[i];
  56. if(stpos==4) continue;
  57. if(i==edx&&stpos==edy){
  58. if(color==1) continue;
  59. LL curhash = hax + powt[4*i+stpos] * color;
  60. if(vis.count(curhash)) continue;
  61. else vis.insert(curhash);
  62. now.mat[i][stpos] = color;
  63. if(check(now)) tot++;
  64. now.mat[i][stpos] = 0;
  65. }
  66. else{
  67. LL curhash = hax + powt[4*i+stpos] * color;
  68. if(vis.count(curhash)) continue;
  69. else vis.insert(curhash);
  70. now.mat[i][stpos] = color;
  71. if(!check(now)){
  72. now.stp[i]++;
  73. now.hashval = curhash;
  74. now.curcol ^= 3;
  75. que.push(now);
  76. now.curcol ^= 3;
  77. now.hashval = hax;
  78. now.stp[i]--;
  79. }
  80. now.mat[i][stpos] = 0;
  81. }
  82. }
  83. }
  84. return tot;
  85. }
  86. int main(){
  87. scanf("%d %d %d",&st,&edx,&edy);
  88. st--,edx--, edy--;
  89. edx^=edy^=edx^=edy;
  90. powt[0] = 1;
  91. for(int i = 1; i <= 18; i++) powt[i] = powt[i-1] * 10;
  92. printf("%d\n",bfs());
  93. return 0;
  94. }

\(C.Game\ Map\)

先按无向图连边,然后按边连着的两个点的度数重新构图,然后跑记忆化搜索即可

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 3e5+7;
  6. int n,m,deg[MAXN],f[MAXN];
  7. vector<int> G[MAXN],newG[MAXN];
  8. void rebuild(){
  9. for(int u = 1; u <= n; u++){
  10. for(int v : G[u]){
  11. if(deg[v]>deg[u]) newG[u].emplace_back(v);
  12. }
  13. }
  14. }
  15. int solve(int u){
  16. if(f[u]!=-1) return f[u];
  17. f[u] = 0;
  18. for(int v : newG[u]) f[u] = max(f[u],solve(v));
  19. f[u]++;
  20. return f[u];
  21. }
  22. int main(){
  23. scanf("%d %d",&n,&m);
  24. for(int i = 1; i <= m; i++){
  25. int u,v;
  26. scanf("%d %d",&u,&v);
  27. u++, v++;
  28. G[u].emplace_back(v);
  29. G[v].emplace_back(u);
  30. deg[u]++; deg[v]++;
  31. }
  32. rebuild();
  33. memset(f,255,sizeof(f));
  34. for(int i = 1; i <= n; i++) if(f[i]==-1) solve(i);
  35. printf("%d\n",*max_element(f+1,f+1+n));
  36. return 0;
  37. }

\(D.Happy\ Number\)

打表找规律

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. map<int, int> mp;
  4. int main(){
  5. int n; cin>>n;
  6. mp[1]++,mp[19]++,mp[82]++,mp[68]++,mp[100]++;
  7. int t=5;
  8. while(t--){
  9. for(int i=1;i<=999;i++){
  10. int tmp=i, s=0;
  11. while(tmp){
  12. s+=(tmp%10)*(tmp%10);
  13. tmp/=10;
  14. }
  15. if(mp.count(s)){
  16. mp[i]++;
  17. }
  18. }
  19. }
  20. int tmp=n, s=0;
  21. while(tmp){
  22. s+=(tmp%10)*(tmp%10);
  23. tmp/=10;
  24. }
  25. if(mp[s])cout<<"HAPPY";
  26. else cout<<"UNHAPPY";
  27. return 0;
  28. }

\(E.How\ Many\ to\ Be\ Happy?\)

对于题给的每一条边,问最少删掉几条边能使这条边出现在最小生成树中

按照Kruskal的方法建最小生成树的时候,是贪心地优先考虑权值小的边,判断这条边连接的两个点是否已经联通。

现在如果要选定一条边加进去,那么必然在遍历到它之前,这条边所连的两个点没有联通,使得这两个点不连通所删掉的最少边就是答案,其实就是最小割的模型,考虑把所有小于该边权值的边加到图中然后跑最大流即可

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 555;
  6. const int INF = 0x3f3f3f3f;
  7. int n,m,rk[MAXN],iter[MAXN];
  8. pair<pair<int,int>,int> es[MAXN];
  9. struct EDGE{
  10. int to,cap,rev;
  11. EDGE(){}
  12. EDGE(int _to, int _cap, int _rev){
  13. to = _to;
  14. cap = _cap;
  15. rev = _rev;
  16. }
  17. };
  18. vector<EDGE> G[MAXN];
  19. void ADDEDGE(int u, int v, int cap){
  20. G[u].emplace_back(EDGE(v,cap,(int)G[v].size()));
  21. G[v].emplace_back(EDGE(u,0,(int)G[u].size()-1));
  22. }
  23. bool BFS(int S, int T){
  24. queue<int> que;
  25. memset(iter,0,sizeof(iter));
  26. memset(rk,0,sizeof(rk));
  27. rk[S] = 1;
  28. que.push(S);
  29. while(!que.empty()){
  30. int u = que.front();
  31. que.pop();
  32. for(auto e : G[u]){
  33. if(!e.cap || rk[e.to]) continue;
  34. rk[e.to] = rk[u] + 1;
  35. que.push(e.to);
  36. }
  37. }
  38. return rk[T]!=0;
  39. }
  40. int dfs(int u, int T, int f){
  41. if(u==T) return f;
  42. for(int &i = iter[u]; i < (int)G[u].size(); i++){
  43. EDGE &e = G[u][i];
  44. if(!e.cap || rk[e.to]!=rk[u]+1) continue;
  45. int d = dfs(e.to,T,min(f,e.cap));
  46. if(d){
  47. e.cap -= d;
  48. G[e.to][e.rev].cap += d;
  49. return d;
  50. }
  51. }
  52. return 0;
  53. }
  54. int Dinic(int S, int T){
  55. int flow = 0;
  56. while(BFS(S,T)){
  57. int d = dfs(S,T,INF);
  58. while(d){
  59. flow += d;
  60. d = dfs(S,T,INF);
  61. }
  62. }
  63. return flow;
  64. }
  65. int solve(int ID){
  66. for(int i = 0; i < MAXN; i++) G[i].clear();
  67. int S = es[ID].first.first, T = es[ID].first.second;
  68. for(int i = 1; i <= m; i++){
  69. if(es[i].second>=es[ID].second) break;
  70. ADDEDGE(es[i].first.first,es[i].first.second,1);
  71. ADDEDGE(es[i].first.second,es[i].first.first,1);
  72. }
  73. return Dinic(S,T);
  74. }
  75. int main(){
  76. scanf("%d %d",&n,&m);
  77. for(int i = 1; i <= m; i++) scanf("%d %d %d",&es[i].first.first,&es[i].first.second,&es[i].second);
  78. sort(es+1,es+1+m,[](const pair<pair<int,int>,int> &A, const pair<pair<int,int>,int> &B){
  79. return A.second < B.second;
  80. });
  81. int res = 0;
  82. for(int i = 1; i <= m; i++) res += solve(i);
  83. printf("%d\n",res);
  84. return 0;
  85. }

\(F.Philosopher's\ Walk\)

按每一步所在块的位置(1/4为1块)递归即可,注意坐标变换

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. int n,m;
  6. pair<int,int> solve(int k, int step){
  7. if(k==1){
  8. if(step==1) return make_pair(1,1);
  9. else if(step==2) return make_pair(1,2);
  10. else if(step==3) return make_pair(2,2);
  11. else return make_pair(2,1);
  12. }
  13. int tot = (1<<k)<<k;
  14. int perstep = tot>>2;
  15. if(step>perstep*3){
  16. auto p = solve(k-1,step-perstep*3);
  17. return make_pair((1<<k)+1-p.second,(1<<(k-1))+1-p.first);
  18. }
  19. else if(step>perstep*2){
  20. auto p = solve(k-1,step-perstep*2);
  21. return make_pair((1<<(k-1))+p.first,(1<<(k-1))+p.second);
  22. }
  23. else if(step>perstep){
  24. auto p = solve(k-1,step-perstep);
  25. return make_pair(p.first,(1<<(k-1))+p.second);
  26. }
  27. else{
  28. auto p = solve(k-1,step);
  29. return make_pair(p.second,p.first);
  30. }
  31. }
  32. int main(){
  33. scanf("%d %d",&n,&m);
  34. auto p = solve(log2(n),m);
  35. printf("%d %d\n",p.first,p.second);
  36. return 0;
  37. }

\(G.Rectilinear\ Regions\)

给出两条阶梯型折线,问B线在A线上面所围成的面积有多少,一共有多少块围成的区域

如果两折线的单调性不一样的话就直接输出0,如果都是单调递减的话把两条线都关于x轴对称翻着就是两个单调递增的阶梯折线了

扫描一遍就完了

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int INF = 0x3f3f3f3f;
  6. const int MAXN = 1e5+7;
  7. using LL = int_fast64_t;
  8. int ya,yb,n,m,tot,x;
  9. pair<pair<int,int>,int> vert[MAXN<<1];
  10. int main(){
  11. scanf("%d %d",&n,&m);
  12. int d1,d2;
  13. scanf("%d",&ya);
  14. for(int i = 1; i <= n; i++){
  15. tot++;
  16. vert[tot].second = 0;
  17. scanf("%d %d",&vert[tot].first.first,&vert[tot].first.second);
  18. d1 = vert[tot].first.second>ya?1:-1;
  19. }
  20. scanf("%d",&yb);
  21. for(int i = 1; i <= m; i++){
  22. tot++;
  23. vert[tot].second = 1;
  24. scanf("%d %d",&vert[tot].first.first,&vert[tot].first.second);
  25. d2 = vert[tot].first.second>yb?1:-1;
  26. }
  27. if(d1!=d2) return puts("0 0"), 0;
  28. if(d1<0){
  29. ya *= -1;
  30. yb *= -1;
  31. swap(ya,yb);
  32. for(int i = 1; i <= tot; i++) {
  33. vert[i].first.second *= -1;
  34. vert[i].second ^= 1;
  35. }
  36. }
  37. sort(vert+1,vert+1+tot,[](const pair<pair<int,int>,int> &A, const pair<pair<int,int>,int> &B){
  38. return A.first.first < B.first.first;
  39. });
  40. int cur = 1;
  41. while(cur <= tot){
  42. int tpya = ya;
  43. int tpyb = yb;
  44. if(vert[cur].second==1){
  45. tpyb = vert[cur].first.second;
  46. if(ya<yb) ya = tpya, yb = tpyb;
  47. else{
  48. if(tpya<tpyb){
  49. x = vert[cur].first.first;
  50. ya = tpya, yb = tpyb;
  51. cur++;
  52. break;
  53. }
  54. else ya = tpya,yb = tpyb;
  55. }
  56. }
  57. else ya = vert[cur].first.second;
  58. cur++;
  59. }
  60. LL area = 0, tparea = 0, regions = 0;
  61. bool tag = true;
  62. for(int i = cur; i <= tot; i++){
  63. if(vert[i].second==0){
  64. if(tag){
  65. tparea += 1ll * (vert[i].first.first-x) * (yb-ya);
  66. ya = vert[i].first.second;
  67. x = vert[i].first.first;
  68. if(ya>=yb){
  69. tag = false;
  70. area += tparea;
  71. regions++;
  72. tparea = 0;
  73. }
  74. }
  75. else{
  76. ya = vert[i].first.second;
  77. x = vert[i].first.first;
  78. }
  79. }
  80. else{
  81. if(tag){
  82. tparea += 1ll * (vert[i].first.first-x) * (yb-ya);
  83. yb = vert[i].first.second;
  84. x = vert[i].first.first;
  85. }
  86. else{
  87. yb = vert[i].first.second;
  88. x = vert[i].first.first;
  89. if(yb>ya) tag = true;
  90. }
  91. }
  92. }
  93. printf("%I64d %I64d\n",regions,area);
  94. return 0;
  95. }

\(H.Rock\ Paper\ Scissors\)

先把字符串转化一下,把要匹配的字符变成相同字符,把每个字符分开来考虑,然后把两个字符串看作两个多项式\(f(x),g(x)\),把当前考虑匹配的字符的系数设为\(1\),不是需要匹配的系数设为\(0\),则初始匹配点为\(pos\)答的案就是\(ans[pos]=\sum_{i=0}^{m-1}f[pos+i]*g[i]\)

把第二个串翻转得到:\(ans[pos]=\sum_{i=0}^{m-1}f[pos+i]g[m-1-i]\)答案就是\(f\)和\(g\)卷积的第\(pos+m-1\)次项的系数

分三次每次做三次FFT即可

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 4e5+7;
  6. const double Pi = acos(-1);
  7. int n,m,limit,l,r[MAXN],ans[MAXN];
  8. char s[MAXN],t[MAXN];
  9. char RSP[3] = {'R','S','P'};
  10. struct Complex{
  11. double x,y;
  12. Complex(double _x = 0, double _y = 0){ x = _x; y = _y; }
  13. Complex operator + (const Complex rhs){ return Complex(x+rhs.x,y+rhs.y); }
  14. Complex operator - (const Complex rhs){ return Complex(x-rhs.x,y-rhs.y); }
  15. Complex operator * (const Complex rhs){ return Complex(x*rhs.x-y*rhs.y,x*rhs.y+y*rhs.x); }
  16. }A[MAXN],B[MAXN];
  17. void FFT(Complex *arr, int inv){
  18. for(int i = 0; i < limit; i++) if(i<r[i]) swap(arr[i],arr[r[i]]);
  19. for(int len = 1; len < limit; len <<= 1){
  20. Complex wn(cos(Pi/len),inv*sin(Pi/len));
  21. for(int R = 0; R < limit; R += (len<<1)){
  22. Complex w(1,0);
  23. for(int i = R; i < R+len; i++,w = w*wn){
  24. Complex x = arr[i];
  25. Complex y = w * arr[i+len];
  26. arr[i] = x + y;
  27. arr[i+len] = x - y;
  28. }
  29. }
  30. }
  31. }
  32. int main(){
  33. scanf("%d %d %s %s",&n,&m,s,t);
  34. for(int i = 0; i < m; i++){
  35. if(t[i]=='R') t[i] = 'S';
  36. else if(t[i]=='S') t[i] = 'P';
  37. else t[i] = 'R';
  38. }
  39. limit = 1, l = 0;
  40. while(limit<=n+m) limit <<= 1, l++;
  41. for(int i = 0; i < limit; i++) r[i] = ((r[i>>1]>>1) | ((i&1)<<(l-1)));
  42. reverse(t,t+m);
  43. for(int ch = 0; ch < 3; ch++){
  44. for(int i = 0; i < limit; i++){
  45. A[i].x = A[i].y = 0;
  46. B[i].x = B[i].y = 0;
  47. }
  48. for(int i = 0; i < n; i++) if(s[i]==RSP[ch]) A[i].x = 1;
  49. for(int i = 0; i < m; i++) if(t[i]==RSP[ch]) B[i].x = 1;
  50. FFT(A,1);
  51. FFT(B,1);
  52. for(int i = 0; i < limit; i++) A[i] = A[i] * B[i];
  53. FFT(A,-1);
  54. for(int i = 0; i < limit; i++) ans[i] += (int)(A[i].x/limit+0.5);
  55. }
  56. int maxx = 0;
  57. for(int i = 0; i < n; i++) maxx = max(maxx,ans[m+i-1]);
  58. printf("%d\n",maxx);
  59. return 0;
  60. }

\(I.Slot\ Machines\)

找起始位置+最小循环节的最小值,可以把每个位置开始的最小循环节找出来然后枚举一下即可

把串翻转然后建出Next数组,i点开始向前的最小循环节长度就是\(i-next[i]\)

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 1e6+7;
  6. int n,k,p,A[MAXN],f[MAXN];
  7. int main(){
  8. scanf("%d",&n);
  9. for(int i = 1; i <= n; i++) scanf("%d",&A[i]);
  10. int len = 0, ptr = 2;
  11. k = n-1, p = 1;
  12. reverse(A+1,A+1+n);
  13. f[1] = 0;
  14. while(ptr<=n){
  15. if(A[ptr]==A[len+1]) f[ptr++] = ++len;
  16. else{
  17. if(len) len = f[len];
  18. else f[ptr++] = len;
  19. }
  20. }
  21. for(int i = 1; i <= n; i++){
  22. int tp = i - f[i];
  23. int tk = n - i;
  24. if(tp+tk<p+k||(tp+tk==p+k&&p>tp)){
  25. p = tp;
  26. k = tk;
  27. }
  28. }
  29. printf("%d %d\n",k,p);
  30. return 0;
  31. }

\(J.Strongly\ Matchable\)

\(K.Untangling\ Chain\)

和初始长度无关,只和方向有关,考虑从当前点开始往某个方向延伸出一条边,到达某个终止位置,只要这个位置的两侧都没有任何其他点,下一次折线必然可以选出一个性质相同的位置,记录两个坐标轴访问最左端的位置和最右端的位置即可。

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 2e5+7;
  6. const int O = 1e5;
  7. int n,xmin,xmax,ymin,ymax;
  8. int main(){
  9. scanf("%d",&n);
  10. int curdir = 0, cx = O, cy = O;
  11. xmin = xmax = ymin = ymax = O;
  12. for(int i = 1; i <= n; i++){
  13. if(curdir==0){
  14. printf("%d ",ymax+1-cy);
  15. ymax = cy = ymax+1;
  16. }
  17. else if(curdir==1){
  18. printf("%d ",xmax+1-cx);
  19. xmax = cx = xmax+1;
  20. }
  21. else if(curdir==2){
  22. printf("%d ",cy-ymin+1);
  23. ymin = cy = ymin-1;
  24. }
  25. else if(curdir==3){
  26. printf("%d ",cx-xmin+1);
  27. xmin = cx = xmin-1;
  28. }
  29. int dir;
  30. scanf("%d %d",&dir,&dir);
  31. curdir = (curdir+dir+4)%4;
  32. }
  33. puts("");
  34. return 0;
  35. }

\(L.Vacation\ Plans\)

枚举天数找最短路,天数上限大概是\(n^3\)

  1. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  5. const int MAXN = 55;
  6. const int MAXNP = MAXN * MAXN * MAXN;
  7. using LL = int_fast64_t;
  8. const LL INF = 0x3f3f3f3f3f3f3f3f;
  9. int p;
  10. struct Country{
  11. int n,m,h[MAXN],airport;
  12. LL f[MAXNP][MAXN];
  13. struct EDGE{
  14. int u, v, c;
  15. EDGE(){}
  16. EDGE(int _u, int _v, int _c){ u = _u, v = _v, c = _c; }
  17. };
  18. vector<EDGE> G;
  19. }cont[4];
  20. int main(){
  21. scanf("%d",&p);
  22. for(int pp = 1; pp <= p; pp++){
  23. scanf("%d %d",&cont[pp].n,&cont[pp].m);
  24. for(int i = 1; i <= cont[pp].n;i++) scanf("%d",&cont[pp].h[i]);
  25. for(int i = 1; i <= cont[pp].m; i++){
  26. int u, v, c;
  27. scanf("%d %d %d",&u,&v,&c);
  28. cont[pp].G.emplace_back(Country::EDGE(u,v,c));
  29. }
  30. scanf("%d",&cont[pp].airport);
  31. }
  32. for(int k = 1; k <= p; k++){
  33. memset(cont[k].f,INF,sizeof(cont[k].f));
  34. cont[k].f[0][1] = 0;
  35. for(int day = 1; day < MAXNP; day++){
  36. for(int i = 1; i <= cont[k].n; i++) cont[k].f[day][i] = min(cont[k].f[day][i],cont[k].f[day-1][i]+cont[k].h[i]);
  37. for(auto e : cont[k].G) cont[k].f[day][e.v] = min(cont[k].f[day][e.v],cont[k].f[day-1][e.u]+e.c);
  38. }
  39. }
  40. LL res = INF;
  41. for(int i = 0; i < MAXNP; i++){
  42. LL tot = 0;
  43. for(int k = 1; k <= p; k++){
  44. if(cont[k].f[i][cont[k].airport]==INF){
  45. tot = INF;
  46. break;
  47. }
  48. tot += cont[k].f[i][cont[k].airport];
  49. }
  50. res = min(res,tot);
  51. }
  52. printf("%I64d\n",res);
  53. return 0;
  54. }

2017-2018 ACM-ICPC, Asia Daejeon Regional Contest PART(10/12)的更多相关文章

  1. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  2. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  3. 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K

    传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...

  4. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

  5. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  6. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  7. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  8. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  9. Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖

    题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...

随机推荐

  1. Petalinux和Vivado的安装

    Petalinux和Vivado的安装 背景 我是搞软件的, FPGA这块不太了解.由于机缘巧合,最近有接触到这块的开发.所以先挖一坑. 先声明我不是专业搞这块的,所以对这块的内容理解可能会有偏差,以 ...

  2. halcon案例学习之cbm_label_simple

    *cbm_label_simple 程序说明:*这个示例程序展示了如何使用基于组件的匹配来定位复合对象.在这种情况下,应该在图像中找到一个标签,用户既不知道其中的组件,也不知道它们之间的关系.因此,创 ...

  3. MongoDB的管理-深度长文

    (1) 启动和停止MongoDB: Ubuntu18下启动关闭MongoDB 启动MongoDB: 方法一: systemctl start mongod.service 方法二: 在MongoDB的 ...

  4. ctfhub技能树—RCE—过滤空格

    打开靶机 查看页面信息 开始尝试注入 127.0.0.1 || ls 尝试绕过 127.0.0.1||ls 使用cat命令查看flag 127.0.0.11||cat<flag_10872536 ...

  5. PeleeNet:精修版DenseNet,速度猛增至240FPS | NeurIPS 2018

    PeleeNet是DenseNet的一个变体,没有使用流行的深度可分离卷积,PeleeNet和Pelee仅通过结构上的优化取得了很不错的性能和速度,读完论文可以学到很多网络设计的小窍门.   来源:晓 ...

  6. ASP.NET Core错误处理中间件[4]: 响应状态码页面

    StatusCodePagesMiddleware中间件与ExceptionHandlerMiddleware中间件类似,它们都是在后续请求处理过程中"出错"的情况下利用一个错误处 ...

  7. IP2188中文资料书

    IP2188 是一款集成 12 种.用于 USB 输出端口的快充协议 IC,支持 USB 端口充电协议.支持 11种快充协议,包括 USB TypeC PD2.0/PD3.0/PPS DFP,HVDC ...

  8. CMU数据库(15-445)实验2-b+树索引实现(上)

    Lab2 在做实验2之前请确保实验1结果的正确性.不然你的实验2将无法正常进行 环境搭建地址如下 https://www.cnblogs.com/JayL-zxl/p/14307260.html 实验 ...

  9. 阿里云镜像仓库镜像迁移至私有Harbor

    下载镜像同步工具 wget https://goodrain-delivery.oss-cn-hangzhou.aliyuncs.com/boe/image-syncer && chm ...

  10. 对象存储 COS 帮您轻松搞定跨域访问需求

    背景 早期为了避免 CSRF(跨站请求伪造) 攻击,浏览器引入了 "同源策略" 机制.如果两个 URL 的协议,主机名(域名/IP),端口号一致,则视为这两个 URL " ...