Claris大爷出的一套模拟题。问别人要到了一份题,加深了自己NOIp要滚粗的感觉。

Matser

zzDP题,我只能说我第一遍写的时候还写崩了QAQ。

  1. //master
  2. //by Cydiater
  3. //2016.10.21
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <cstdio>
  7. #include <cstring>
  8. #include <string>
  9. #include <algorithm>
  10. #include <queue>
  11. #include <map>
  12. #include <ctime>
  13. #include <cmath>
  14. #include <iomanip>
  15. using namespace std;
  16. #define ll long long
  17. #define up(i,j,n) for(int i=j;i<=n;i++)
  18. #define down(i,j,n) for(int i=j;i>=n;i--)
  19. #define FILE "master"
  20. #define cmax(a,b) a=max(a,b)
  21. #define cmin(a,b) a=min(a,b)
  22. const int MAXN=305;
  23. const int oo=0x3f3f3f3f;
  24. inline int read(){
  25. char ch=getchar();int x=0,f=1;
  26. while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
  27. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  28. return x*f;
  29. }
  30. int N,K,f[MAXN][MAXN][MAXN][2];
  31. char s1[MAXN],s2[MAXN];
  32. namespace solution{
  33. void init(){
  34. N=read();K=read();
  35. scanf("%s",s1+1);
  36. scanf("%s",s2+1);
  37. }
  38. void DP(){
  39. memset(f,0,sizeof(f));
  40. up(i,1,N)up(j,1,N)up(k,0,K){
  41. f[i][j][k][0]=max(f[i][j-1][k][0],f[i-1][j][k][0]);
  42. if(k>0)cmax(f[i][j][k][1],f[i-1][j-1][k-1][1]+1);
  43. if(s1[i]==s2[j]){
  44. cmax(f[i][j][k][1],f[i-1][j-1][k][1]+1);
  45. }
  46. cmax(f[i][j][k][0],f[i][j][k][1]);
  47. }
  48. }
  49. void output(){
  50. cout<<f[N][N][K][0]<<endl;
  51. }
  52. }
  53. int main(){
  54. freopen(FILE".in","r",stdin);
  55. freopen(FILE".out","w",stdout);
  56. using namespace solution;
  57. init();
  58. DP();
  59. output();
  60. return 0;
  61. }

Tour

通过这道题学到了bitset的简单用法,很实用。

那道题的时候想了想搞到了70分的做法,卡在了如何$O(1)$求三元环的算法上,事实证明不一定要$O(1)$,用bitset小优化一下就行了。

这道题充分说明了降维思想的重要性。

  1. //tour
  2. //by Cydiater
  3. //2016.10.21
  4. #include <iostream>
  5. #include <cstring>
  6. #include <string>
  7. #include <algorithm>
  8. #include <queue>
  9. #include <map>
  10. #include <ctime>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <cstdlib>
  14. #include <bitset>
  15. #include <cstdio>
  16. using namespace std;
  17. #define ll long long
  18. #define up(i,j,n) for(int i=j;i<=n;i++)
  19. #define down(i,j,n) for(int i=j;i>=n;i--)
  20. #define FILE "tour"
  21. #define LENGTH 1500
  22. #define bs bitset<LENGTH>
  23. const int MAXN=1505;
  24. const int oo=0x3f3f3f3f;
  25. inline int read(){
  26. char ch=getchar();int x=0,f=1;
  27. while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
  28. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  29. return x*f;
  30. }
  31. int N,LEN,cnt[MAXN];
  32. bool mat[MAXN][MAXN];
  33. char s[MAXN];
  34. ll ans=0;
  35. struct BITSET{
  36. bs v;
  37. }Match[MAXN];
  38. namespace solution{
  39. inline int lowbit(int i){return i&(-i);}
  40. void init(){
  41. N=read();LEN=(N-1)/LENGTH+1;
  42. memset(cnt,0,sizeof(cnt));
  43. up(i,1,N){
  44. scanf("%s",s+1);
  45. up(j,1,N)if((mat[i][j]=s[j]-'0')==1)cnt[i]++;
  46. int now=1;
  47. up(j,1,LEN){
  48. bs S(0),tmp;
  49. up(k,now,min(N,now+LENGTH-1))
  50. if(mat[i][k])
  51. Match[i].v[k-now]=1;;
  52. now+=LENGTH;
  53. }
  54. }
  55. }
  56. int get(int x,int y){
  57. return (Match[x].v&Match[y].v).count();
  58. }
  59. void slove(){
  60. up(i,1,N)up(j,i+1,N)if(i!=j&&mat[i][j]){
  61. ans+=(ll)(cnt[i]-1)*(ll)(cnt[j]-1)*2LL;
  62. ans-=get(i,j)*2LL;
  63. }
  64. }
  65. void output(){
  66. cout<<ans<<endl;
  67. }
  68. }
  69. int main(){
  70. freopen(FILE".in","r",stdin);
  71. freopen(FILE".out","w",stdout);
  72. using namespace solution;
  73. init();
  74. slove();
  75. output();
  76. //cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
  77. return 0;
  78. }

Walk

做的时候最没有头绪的一道题。需要在原图上加点建立一个新图,新建的分别代表$[0,2^{20}-1]$上的每一个点,然后每个点向其二进制下有且只要以为不为1的连边,然后对于原图上的每个点,指向对应的新点一条边权为1的边,然后反向连一条边权为0的边。然后大力BFS,需要注意的是每次应该把所有与其距离为0的都加入队列中。

  1. //walk
  2. //by Cydiater
  3. //2016.10.23
  4. #include <iostream>
  5. #include <cstring>
  6. #include <string>
  7. #include <algorithm>
  8. #include <queue>
  9. #include <map>
  10. #include <bitset>
  11. #include <iomanip>
  12. #include <cstdlib>
  13. #include <cstdio>
  14. #include <cmath>
  15. #include <ctime>
  16. using namespace std;
  17. #define ll long long
  18. #define up(i,j,n) for(int i=j;i<=n;i++)
  19. #define down(i,j,n) for(int i=j;i>=n;i--)
  20. #define FILE "walk"
  21. const int MAXN=2e6+5;
  22. const int oo=0x3f3f3f3f;
  23. inline int read(){
  24. char ch=getchar();int x=0,f=1;
  25. while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
  26. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  27. return x*f;
  28. }
  29. int N,M,V[1300000],LINK[1300000],len=0,head,tail,q[1300000],dis[1300000];
  30. bool vis[1300000];
  31. struct edge{
  32. int y,next,v;
  33. }e[MAXN*10];
  34. namespace solution{
  35. inline void insert(int x,int y,int v){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;e[len].v=v;}
  36. void init(){
  37. N=read();M=read();
  38. up(i,1,N)V[i]=read();
  39. up(i,1,M){
  40. int x=read(),y=read();
  41. insert(x,y,1);
  42. }
  43. up(i,0,(1<<20)-1){
  44. up(j,0,19)if(((1<<j)&(i))==(1<<j)){
  45. int x=i,y=i^(1<<j);
  46. insert(N+1+x,N+1+y,0);
  47. }
  48. }
  49. up(i,1,N){
  50. insert(i,N+1+V[i],1);
  51. insert(N+1+V[i],i,0);
  52. }
  53. }
  54. void ADD(int node){
  55. q[++tail]=node;vis[node]=1;
  56. for(int i=LINK[node];i;i=e[i].next)if(!vis[e[i].y]&&!e[i].v){
  57. dis[e[i].y]=dis[node];
  58. ADD(e[i].y);
  59. }
  60. }
  61. void slove(){
  62. memset(vis,0,sizeof(vis));
  63. memset(dis,0,sizeof(dis));
  64. head=1;tail=0;q[++tail]=1;
  65. dis[1]=0;vis[1]=1;
  66. for(;head<=tail;head++){
  67. int node=q[head];
  68. for(int i=LINK[node];i;i=e[i].next)if(!vis[e[i].y]){
  69. dis[e[i].y]=dis[node]+e[i].v;
  70. ADD(e[i].y);
  71. }
  72. }
  73. up(i,2,N)if(dis[i]==0)dis[i]=-1;
  74. }
  75. void output(){
  76. up(i,1,N)printf("%d\n",dis[i]);
  77. }
  78. }
  79. int main(){
  80. freopen(FILE".in","r",stdin);
  81. freopen(FILE".out","w",stdout);
  82. using namespace solution;
  83. init();
  84. slove();
  85. output();
  86. return 0;
  87. }

NOIp2016 十连测 round1的更多相关文章

  1. noip2016十连测round1

    A:String Master 题目:所谓最长公共子串,比如串 A:"abcde",串 B:"jcdkl",则它们的最长公共子串为串 "cd" ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. noip2016十连测round3

    A:平均数 题意:有一天,小 A 得到了一个长度为 n 的序列. 他把这个序列的所有连续子序列都列了出来,并对每一个子序列都求了其平均值,然后他把这些平均值写在纸上,并对它们进行排序,最后他报出了第 ...

  4. noip2016十连测round2

    A: Divisors 题意:给定 m 个不同的正整数 a 1 ,a 2 ,...,a m ,请对 0 到 m 每一个 k 计算,在区间 [1,n] 里有多少正整数 是 a 中恰好 k 个数的约数. ...

  5. Problem C: [noip2016十连测第五场]travel (构造+贪心)

    题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...

  6. bzoj 5216 [Lydsy2017省队十连测]公路建设 线段树维护 最小生成树

    [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 93  Solved: 53[Submit][Status][ ...

  7. bzoj 5216: [Lydsy2017省队十连测]公路建设

    5216: [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 66  Solved: 37[Submit][St ...

  8. 提高十连测day3

    提高十连测day3 A 我们可以枚举两个 $ 1 $ 之间的相隔距离,然后计算形如 $ 00100100 \cdots $ 的串在原串中最⻓⼦序列匹配即可,复杂度 $ O(n^2) $ .寻找 $ S ...

  9. ZROI2019 提高十连测

    额 掰手指头一数 特么又是第三年十连测了= = 2017一场没打 那时候好像一场比赛也就100人左右 2018前几场还都好好补了 后来开始放飞自我了 这时候一场有150人还多了 2019想让今年的No ...

随机推荐

  1. [转]oracle 实施方法论学习心得

      本周由部门新入职的同事为我们分享oracle实施方法论,本次重点围绕项目启动会来做介绍,并着重介绍了oracle与我们不一样的地方.收获颇丰,简单总结几个值得学习借鉴的要点: 1.      细节 ...

  2. Ignite 配置更新Oracle JDBC Drive

           如果使用Oracle 12C 作为Ignite 的Repository的话,在Repository Createion Wizard的配置过程中,会出现ORA-28040:No matc ...

  3. Python基础2

    入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'yuxiaozheng' print name 外层变量,可以被 ...

  4. Oracle索引梳理系列(六)- Oracle索引种类之函数索引

    版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...

  5. IntelliJ IDEA 配置运行程序

    IntelliJ IDEA 对于Javaer开发来说还是很nice的,就是第一次用可能配置项有点生疏,这里就记录一下IntelliJ IDEA 配置运行程序. 1. 点击Edit Config... ...

  6. 设置DIV可编辑

    <div id="move" contentEditable="true">可编辑</div> 设置contentEditable属性可 ...

  7. Shell基础学习小结

    0 shell基础概念 Shell是解释性语言,使用脚本编程语言的好处是,它们多半运行在比编译型语言还高的层级,能够轻易处理文件与目录之类的对象:缺点是它们的效率通常不如编译型语言.Shell命令有本 ...

  8. JS重载

    Js 不支持函数的重载,可以用相同的名字在同一作用区域,定义两个函数,而不会引起错误,但真正使用的是最后一个. Js 不会验证传递给函数的参数个数是否和函数定义的参数的个数相同,开发人员定义的函数都可 ...

  9. http协议进阶(三)http报文

    一.报文流 http报文是在http应用程序之间发送的数据块(也可称为数据包).这些数据块以一些文本的元信息(meta-information)开头,描述了报文的内容及含义,后面跟着 可选的数据部分, ...

  10. android第一行代码-1.项目结构

    0.项目结构 一个简单的android项目结构大致如下 入口就是MainActivity这个类,如果对于一个陌生的项目,最好的办法是看AndroidMainifest.xml,如下 <?xml ...