2019.3.18

C O D E

T1

树上直接贪心,环上for一遍贪心


哇说的简单,码了将近一下午终于码出来了

感觉自己码力/写题策略太糟糕了,先是搞了一个细节太多的写法最后不得不弃疗了,然后第二次思路又有问题,最后重构了两遍代码

大概先是需要多想,想清楚了不要先考虑细节,果断写+调

废话结束


对于入度大于一且不在环上的点直接贪心留最大的

对于一个完美无瑕的环直接断最小的(指没有被环以外的点指着)

对于入度大于一且在环上的点,先假装它就是普通的入度大于一的点来做并记录每个点是否断了环上的边和断的边中的最大值;最后把没有删边的不完美的环每个单独拿出来,枚举到底断那一条边修正答案

细节不说了,这种题的细节也没啥可说的。。。

(为了避免伤害眼睛已经删掉了调试语句

  1. #include<cstdio>
  2. #include<vector>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define vint vector<int>
  6. #define vit vector<int>::iterator
  7. using namespace std;
  8. const int N=;
  9. int p[N],noww[N],goal[N];
  10. int rec[N],cst[N],inc[N],col[N];
  11. int deg[N],aset[N],stk[N],vis[N];
  12. int cal[N],cut[N],brk[N],spe[N],mae[N];
  13. int n,dfn,cnt,tot,top; long long ans; vint ve[N],cr[N];
  14. void Link(int f,int t)
  15. {
  16. noww[++cnt]=p[f];
  17. goal[cnt]=t,p[f]=cnt;
  18. }
  19. int Finda(int x)
  20. {
  21. return x==aset[x]?x:aset[x]=Finda(aset[x]);
  22. }
  23. bool Bigcir()
  24. {
  25. int tmp=;
  26. for(int i=;i<=n;i++)
  27. {
  28. if(Finda(i)==i) tmp++;
  29. if(deg[i]!=) return false;
  30. }
  31. return tmp==;
  32. }
  33. void DFS(int nde)
  34. {
  35. stk[++top]=nde,vis[nde]=dfn;
  36. for(int i=p[nde],g;i;i=noww[i])
  37. if(!vis[g=goal[i]]) DFS(g);
  38. else if(vis[g]==dfn)
  39. {
  40. int ori=g,pts=top; tot++;
  41. while(stk[pts]!=ori)
  42. {
  43. int tmp=stk[pts--];
  44. cr[tot].push_back(tmp);
  45. col[tmp]=tot,inc[tmp]=true;
  46. }
  47. cr[tot].push_back(ori);
  48. col[ori]=tot,inc[ori]=true;
  49. }
  50. top--;
  51. }
  52. int main()
  53. {
  54. scanf("%d",&n);
  55. for(int i=;i<=n;i++) aset[i]=i;
  56. for(int i=;i<=n;i++)
  57. {
  58. scanf("%d%d",&rec[i],&cst[i]);
  59. Link(i,rec[i]),ve[rec[i]].push_back(i);
  60. aset[Finda(i)]=Finda(rec[i]),deg[rec[i]]++;
  61. }
  62. if(Bigcir()) printf(""),exit();
  63. else
  64. {
  65. cst[n+]=1e9;
  66. for(int i=;i<=n;i++)
  67. if(!vis[i]) dfn++,DFS(i);
  68. for(int i=;i<=n;i++)
  69. if(deg[i]>&&inc[i])
  70. {
  71. int t,o=,c=col[i],kao;
  72. for(vit it=ve[i].begin();it!=ve[i].end();it++)
  73. {
  74. if(!cut[t=*it]&&cst[t]>cst[o]) o=t;
  75. if(inc[t]) kao=t;
  76. }
  77. for(vit it=ve[i].begin();it!=ve[i].end();it++)
  78. if(!cut[t=*it]&&t!=o)
  79. {
  80. cut[t]=true,mae[i]=max(mae[i],cst[t]);
  81. if(t==kao) brk[c]=true;
  82. }
  83. cal[c]=true,spe[i]=true;
  84. }
  85. for(int i=;i<=n;i++)
  86. if(deg[i]>&&!inc[i])
  87. {
  88. int t,o=;
  89. for(vit it=ve[i].begin();it!=ve[i].end();it++)
  90. if(!cut[t=*it]&&cst[t]>cst[o]) o=t;
  91. for(vit it=ve[i].begin();it!=ve[i].end();it++)
  92. if((t=*it)!=o) cut[t]=true,deg[rec[t]]--;
  93. }
  94. for(int i=;i<=tot;i++)
  95. if(!cal[i])
  96. {
  97. int t,o=n+;
  98. for(vit it=cr[i].begin();it!=cr[i].end();it++)
  99. if(!cut[(t=*it)]&&cst[t]<cst[o]) o=t;
  100. cut[o]=true,deg[rec[o]]--;
  101. }
  102. }
  103. for(int i=;i<=n;i++)
  104. if(cut[i]) ans+=cst[i];
  105. for(int i=;i<=tot;i++)
  106. if(cal[i]&&!brk[i])
  107. {
  108. int t; long long tep=1e18;
  109. for(vit it=cr[i].begin();it!=cr[i].end();it++)
  110. if(!spe[rec[t=*it]]) tep=min(tep,ans+cst[t]);
  111. else tep=min(tep,ans+cst[t]-mae[rec[t]]);
  112. ans=tep;
  113. }
  114. printf("%lld",ans);
  115. return ;
  116. }

T2

逐行地每次正反都做一遍DP,记录从哪里吃过来,对应地递归吃后面的

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N=,inf=0x3f3f3f3f;
  6. int n,m,vis[N][N],dp[N][N];
  7. char str[N][N];
  8. void Mini(int &x,int y)
  9. {
  10. if(x>y) x=y;
  11. }
  12. bool Out(int a,int b)
  13. {
  14. return a<||b<||a>n||b>m;
  15. }
  16. int DFS(int x,int y,int t)
  17. {
  18. if(Out(x,y)) return ;
  19. int &vs=vis[x][y];
  20. if(~vs) return vs?:inf;
  21. vs=; int ret=;
  22. if(str[x][y]=='Z')
  23. {
  24. if(t<) ret+=DFS(x+,y,)+DFS(x,y+,);
  25. else ret+=DFS(x-,y,)+DFS(x,y-,);
  26. Mini(ret,inf);
  27. }
  28. else
  29. {
  30. if(t==||t==) ret+=DFS(x,y+,)+DFS(x-,y,);
  31. else ret+=DFS(x+,y,)+DFS(x,y-,);
  32. Mini(ret,inf);
  33. }
  34. if(ret!=inf) vs=;
  35. return ret;
  36. }
  37. int main()
  38. {
  39. scanf("%d%d",&n,&m);
  40. for(int i=;i<=n;i++)
  41. scanf("%s",str[i]+);
  42. memset(dp,0x3f,sizeof dp);
  43. for(int i=;i<=n;i++)
  44. {
  45. memset(vis,-,sizeof vis);
  46. for(int j=,t=;j<=m;j++)
  47. t+=DFS(i,j,),Mini(t,inf),Mini(dp[i][j],t);
  48. memset(vis,-,sizeof vis);
  49. for(int j=m,t=;j;j--)
  50. t+=DFS(i,j,),Mini(t,inf),Mini(dp[i][j],t);
  51. }
  52. for(int i=;i<=n;i++)
  53. for(int j=;j<=m;j++)
  54. {
  55. if(dp[i][j]==inf) printf("-1");
  56. else printf("%d",dp[i][j]);
  57. j==m?puts(""):putchar(' ');
  58. }
  59. return ;
  60. }

T3

观察到顺序不影响答案,分块打标记

注意分开处理两边零散块是有顺序的

(已经忘掉有分块这个东西了TAT

  1. #pragma GCC optimize(3)
  2. #include<queue>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #define vint vector<int>
  7. #define gint greater<int>
  8. #define prq priority_queue
  9. using namespace std;
  10. const int N=,Sq=;
  11. int n,m,rd,lp,rp,tg,sqr,tot;
  12. int sus[N],bel[N],lpt[Sq],rpt[Sq];
  13. prq<int> mxx[Sq]; prq<int,vint,gint> tag[Sq];
  14. void Pre()
  15. {
  16. sqr=sqrt(n)+,lpt[tot=]=;
  17. for(int i=;i<=n;i++)
  18. {
  19. bel[i]=(i-)/sqr+;
  20. if(i%sqr==) rpt[tot++]=i,lpt[tot]=i+;
  21. }
  22. n%sqr?rpt[tot]=n:tot--;
  23. }
  24. void Create(int b)
  25. {
  26. mxx[b]=prq<int> ();
  27. for(int i=lpt[b];i<=rpt[b];i++) mxx[b].push(sus[i]);
  28. }
  29. void Release(int b)
  30. {
  31. if(!tag[b].empty())
  32. {
  33. for(int i=lpt[b];i<=rpt[b];i++)
  34. if(tag[b].top()<sus[i])
  35. tag[b].push(sus[i]),sus[i]=tag[b].top(),tag[b].pop();
  36. }
  37. tag[b]=prq<int,vint,gint> ();
  38. }
  39. int Round(int l,int r,int s)
  40. {
  41. if(bel[l]==bel[r])
  42. {
  43. int b=bel[l];
  44. Release(b);
  45. for(int i=l;i<=r;i++)
  46. if(s<sus[i]) swap(s,sus[i]);
  47. Create(b);
  48. }
  49. else
  50. {
  51. int b1=bel[l],b2=bel[r];
  52. Release(b1);
  53. for(int i=l;i<=rpt[b1];i++)
  54. if(s<sus[i]) swap(s,sus[i]); Create(b1);
  55. for(int i=b1+;i<=b2-;i++)
  56. if(s<mxx[i].top())
  57. {
  58. int tmp=mxx[i].top(); mxx[i].pop();
  59. mxx[i].push(s),tag[i].push(s),s=tmp;
  60. }
  61. Release(b2);
  62. for(int i=lpt[b2];i<=r;i++)
  63. if(s<sus[i]) swap(s,sus[i]); Create(b2);
  64. }
  65. return s;
  66. }
  67. int main()
  68. {
  69. scanf("%d%d",&n,&m),Pre();
  70. for(int i=;i<=n;i++) scanf("%d",&sus[i]);
  71. for(int i=;i<=tot;i++) Create(i);
  72. for(int i=;i<=m;i++)
  73. {
  74. scanf("%d%d%d",&lp,&rp,&tg);
  75. if(lp>rp) tg=Round(lp,n,tg),lp=;
  76. printf("%d\n",Round(lp,rp,tg));
  77. }
  78. return ;
  79. }

2019.3.19

肥肠爆芡,因为沙茶博主昨天在学校的煞笔食堂吃坏了肚子,所以这场考试咕咕了

开始补档

T1

一开始找x坐标或y坐标最大的点,然后看下一次转向,左转就走极角最大的,右转就走极角最小的

其实扫一遍就可以,然而我傻乎乎地每次都排了个序

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N=;
  6. struct a{int xp,yp,idx;}o,pt[N],cp[N];
  7. bool cmp(a x,a y)
  8. {
  9. return x.xp==y.xp?x.yp<y.yp:x.xp<y.xp;
  10. }
  11. long long Cha(a x,a y)
  12. {
  13. return 1ll*(x.xp-o.xp)*(y.yp-o.yp)-1ll*(y.xp-o.xp)*(x.yp-o.yp);
  14. }
  15. bool cop(a x,a y)
  16. {
  17. return Cha(x,y)<;
  18. }
  19. int n,m,vis[N],ans[N]; char str[N];
  20. void Solve(int p,int l,int r,a q)
  21. {
  22. vis[q.idx]=true,ans[p]=q.idx;
  23. if(p==n) return;
  24. o=q,sort(cp+l,cp++r,cop);
  25. if(str[p]=='L') Solve(p+,l,r-,cp[r]);
  26. else Solve(p+,l+,r,cp[l]);
  27. }
  28. int main()
  29. {
  30. scanf("%d",&n);
  31. for(int i=;i<=n;i++)
  32. scanf("%d%d",&pt[i].xp,&pt[i].yp),pt[i].idx=i;
  33. scanf("%s",str+);
  34. sort(pt+,pt++n,cmp);
  35. for(int i=;i<=n;i++) cp[i]=pt[i];
  36. Solve(,,n-,pt[n]);
  37. for(int i=;i<=n;i++) printf("%d ",ans[i]);
  38. return ;
  39. }

T2

推性质题,我们发现每个人感染的是一段区间的人,然后就转成了线段覆盖的方案数,树状数组优化

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #define vint vector<int>
  5. #define vit vector<int>::iterator
  6. using namespace std;
  7. const int N=,mod=1e9+;
  8. int n,ans,uni[N],spd[N],bit[N],pre[N],suf[N];
  9. struct a{int pos,spe;}pt[N]; vint ve[N];
  10. bool cmp(a x,a y){return x.pos<y.pos;}
  11. void Add(int &x,int y){x+=y; if(x>=mod) x-=mod;}
  12. void Modify(int x,int y)
  13. {
  14. while(x<=n)
  15. Add(bit[x],y),x+=x&-x;
  16. return;
  17. }
  18. int Query(int x)
  19. {
  20. int ret=;
  21. while(x>)
  22. Add(ret,bit[x]),x-=x&-x;
  23. return ret;
  24. }
  25. int main()
  26. {
  27. register int i;
  28. scanf("%d",&n);
  29. for(i=;i<=n;i++)
  30. scanf("%d%d",&pt[i].pos,&pt[i].spe),uni[i]=pt[i].spe;
  31. sort(pt+,pt++n,cmp),sort(uni+,uni++n);
  32. int lth=unique(uni+,uni++n)-uni-;
  33. for(i=;i<=n;i++) spd[i]=lower_bound(uni+,uni++lth,pt[i].spe)-uni;
  34. for(i=;i<=n;i++) pre[i]=max(pre[i-],spd[i]);
  35. for(i=n,suf[n+]=1e9;i;i--) suf[i]=min(suf[i+],spd[i]);
  36. for(int i=;i<=n;i++) ve[pre[i]].push_back(suf[i]);
  37. for(int i=,t,tmp;i<=n;i++)
  38. for(vit it=ve[i].begin();it!=ve[i].end();it++)
  39. {
  40. t=*it,tmp=(Query(i)-Query(t-)+(t<)+mod)%mod;
  41. Modify(i,tmp); if(i==n) Add(ans,tmp);
  42. }
  43. printf("%d",ans);
  44. return ;
  45. }

T3

这题......

(orz ztb tql)

2019.3.21

T1

容斥/点分治

不想写了摸鱼了咕咕咕了

T2

转化成完全二分图的哈密顿回路,式子随便推推就有了

然后考场推到这里不会去重,搞出来一个整数划分,wsl

去重的方法是我们钦定第一个回路经过左边第一个,然后就有

T3

orz yzh tql

模拟费用流,在每一只鸟进来之后找离这只鸟最近的还有空的点,正确性参考费用流

具体来说要支持树上边权取反和查询到所有合法点的最短路,因为树高只有log暴力爬树DP维护

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N=,inf=1e9;
  6. int nes[N],gu[N],flw[N],dp[N],bes[N],n,m,ans;
  7. void Maintain(int nde)
  8. {
  9. int ls=*nde,rs=*nde+; dp[nde]=inf;
  10. if(ls<=n&&dp[ls]+(flw[ls]>=?:-)<dp[nde])
  11. dp[nde]=dp[ls]+(flw[ls]>=?:-),bes[nde]=bes[ls];
  12. if(rs<=n&&dp[rs]+(flw[rs]>=?:-)<dp[nde])
  13. dp[nde]=dp[rs]+(flw[rs]>=?:-),bes[nde]=bes[rs];
  14. if(nes[nde]&&dp[nde]>=) dp[nde]=,bes[nde]=nde;
  15. }
  16. void Pushup(int nde)
  17. {
  18. Maintain(nde);
  19. if(nde!=) Pushup(nde>>);
  20. }
  21. void Gu(int nde)
  22. {
  23. int x=nde,tmp=,bsf=inf,bsp=,bsn=;
  24. while(x)
  25. {
  26. int tep=tmp+dp[x];
  27. if(tep<bsf) bsf=tep,bsp=bes[x],bsn=x;
  28. tmp+=(flw[x]<=?:-),x>>=;
  29. }
  30. ans+=bsf,nes[bsp]--;
  31. int mem1=nde,mem2=bsp;
  32. while(nde!=bsn) flw[nde]--,nde>>=;
  33. while(bsp!=bsn) flw[bsp]++,bsp>>=;
  34. Pushup(mem1),Pushup(mem2);
  35. }
  36. int main()
  37. {
  38. scanf("%d%d",&n,&m);
  39. for(int i=;i<=n;i++) scanf("%d",&nes[i]);
  40. for(int i=;i<=m;i++) scanf("%d",&gu[i]);
  41. for(int i=n;i;i--) Maintain(i);
  42. for(int i=;i<=m;i++) Gu(gu[i]),printf("%d ",ans);
  43. return ;
  44. }

2019.3.18考试&2019.3.19考试&2019.3.21考试的更多相关文章

  1. LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Sun Jan 13 17:59:19 CST 2019]; root of context hierarch

    在运行项目时出现了:LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via ...

  2. 2019.9.18 csp-s模拟测试46 反思总结

    神志不清: 回去休息(x)继续考试(√) 非常爆炸的一次考试.看错题码完T1回去再看发现自己过于幼稚,T2读完题看着16mb的空间秒出正解然后逻辑出现致命失误100pts->0pts,T3看了一 ...

  3. 2021.8.21考试总结[NOIP模拟45]

    T1 打表 由归纳法可以发现其实就是所有情况的总和. $\frac{\sum_{j=1}^{1<<k}(v_j-v_{ans})}{2^k}$ $code:$ 1 #include< ...

  4. 2021.7.21考试总结[NOIP模拟22]

    终于碾压小熠了乐死了 T1 d 小贪心一波直接出正解,没啥好说的(bushi 好像可以主席树暴力找,但我怎么可能会呢?好像可以堆优化简单找,但我怎么可能想得到呢? 那怎么办?昨天两道单调指针加桶,我直 ...

  5. 9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz!

    9月19号-9月21号丰宁坝上草原行 - 营销系统 - 京东内部论坛 - Powered by Discuz! 9月19号-9月21号丰宁坝上草原行   [复制链接]

  6. 清北学堂2019.7.18 & 清北学堂2019.7.19

    Day 6 钟皓曦 经典题目:石子合并 可以合并任意两堆,代价为数量的异或(^)和 f[s]把s的二进制所对应石子合并成一堆所花代价 枚举s的子集 #include<iostream> u ...

  7. 开机时自动启动的AutoHotkey脚本 2019年07月08日19时06分

    ;;; 开机时自动启动的AutoHotkey脚本;; 此脚本修改时间 2019年06月18日20时48分;; 计时器创建代码段 ------------------------------------ ...

  8. MySQL存储过程-2019/7/18

    MySQL 5.0 版本开始支持存储过程. 存储过程(Stored Procedure)是一种在数据库中存储复杂程序,以便外部程序调用的一种数据库对象. 存储过程是为了完成特定功能的SQL语句集,经编 ...

  9. 2019.8.13 NOIP模拟测试19 反思总结

    最早写博客的一次∑ 听说等会儿还要考试[真就两天三考啊],教练催我们写博客… 大约是出题最友好的一次[虽然我还是炸了],并且数据也非常水…忽视第三题的锅的话的确可以这么说.但是T3数据出锅就是你的错了 ...

随机推荐

  1. Python数据类型-7

    什么数据类型. int 1,2,3用于计算. bool:True,False,用户判断. str:存储少量数据,进行操作 'fjdsal' '二哥','`13243','fdshklj' '战三,李四 ...

  2. Java web错误总结~

    1.java程序中没有错,但是项目上面显示一个红叉的解决办法 错误信息: 报Description  Resource Path Location Type Java compiler level d ...

  3. 07-java学习-方法重载-idea集成开发工具学习-项目-模块-包

    方法重载的概念? 方法重载的好处? 集成开发工具idea的学习 下载 安装 设置 建项目 导入项目 建模块 导入模块 建包 复制粘贴包 建类 复制粘贴类 运行 调试

  4. SprngMVC源码学习

    运行helloWorld示例进入调试界面. DispatcherServlet:前端控制器 DispatcherServlet.doDispatch(HttpServletRequest, HttpS ...

  5. book项目分析

    需求1:用户注册 需求如下: 1)访问注册页面 2)填写注册信息,提交给服务器 3)服务器应该保存用户 4)当用户已经存在----提示用户注册 失败,用户名已存在 5)当用户不存在-----注册成功 ...

  6. Java Script正则表达式语法学习

    今天在做页面交互验证时,在HTML里面第一反应居然用了Java 处理正则表达式的语法... ---------------------------------题记 学习来源 http://www.ru ...

  7. 11-Python3从入门到实战—基础之生成器和迭代器

    Python从入门到实战系列--目录 切片 Python提供切片(Slice)操作符用来获取列表.元组等数据中的部分元素:如,读取列表 list[m:n]:表示获取m-n区间的元素 list[m:n: ...

  8. PAT L2-002 链表去重

    https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184 给定一个带整数键值的链表 L,你需要把其中绝 ...

  9. JavaScript浏览器历史的语法小问题

    https://www.w3schools.com/jsref/met_his_back.asp This is the same as clicking the "Back button& ...

  10. C++拷贝控制

    一.拷贝控制操作 ​ 当定义一个类时,显示或隐式地指定了此类型的对象在拷贝.赋值和销毁时所执行的操作,通过三个特殊的成员函数来控制这些操作,分别是拷贝构造函数,赋值运算符和析构函数.拷贝构造函数定义了 ...