Nowcoder 提高组练习赛-R7

  https://www.nowcoder.com/acm/contest/179#question

  中间空了两场,因为实在是太难了...

  第五场的第二题好像还比较可做,是一个最小生成树的结论题,注意到$2^i$可以认为是二进制下的数,即使把比它小的所有$2^x$全加起来也还是比他小,这一点做题的时候可以用一下.

  第六场的第一题是一道很奇怪的题目,给图上的每条边赋一个权值,求从每个点出发的最长路以及整条路径上所有数字组成一个高进制数的最大字典序(注意最长路可能有很多条).这道题首先缩点,如果走到环里了就是无限长,求出最长路,然后建反图.按照最长路的长度降序排序,再更新前面的值,但是这么做只有$60$分,因为只考虑了每个点前一条边的数字大小,如果有两条边的数字是一样的,就成了随机选择,但是沿着这条边接着走时可能就会发现两条路径一优一劣了.所以好像还要根据每个点目前的字典序大小对边排序...?好麻烦啊.

  

  今天的题看起来好像简单一点?

  A:https://www.nowcoder.com/acm/contest/179/A

  题意概述:小清新模拟题.

  

  1. # include <cstdio>
  2. # include <iostream>
  3. # include <cstring>
  4. # include <string>
  5. # include <cmath>
  6. # include <algorithm>
  7. # define R register int
  8. # define ll long long
  9.  
  10. using namespace std;
  11.  
  12. const int dx[]={-,-,-,,,,,};
  13. const int dy[]={-,,,-,,-,,};
  14. const int maxn=;
  15. int n,m,k,r,no,T,x,y,w;
  16. int act[maxn][maxn],ope[maxn][maxn],vis[maxn][maxn];
  17.  
  18. int main()
  19. {
  20. scanf("%d%d%d",&n,&m,&k);
  21. no=k;
  22. for (R i=;i<=n;++i)
  23. for (R j=;j<=m;++j)
  24. {
  25. scanf("%d",&r);
  26. if(r>) act[i][j]=r;
  27. else act[i][j]=-;
  28. }
  29. for (R i=;i<=n;++i)
  30. for (R j=;j<=m;++j)
  31. scanf("%d",&ope[i][j]);
  32. scanf("%d",&T);
  33. while(T--)
  34. {
  35. scanf("%d%d",&x,&y);
  36. if(ope[x][y]==)
  37. {
  38. printf("-1 -1");
  39. return ;
  40. }
  41. if(vis[x][y])
  42. {
  43. printf("-1 -1");
  44. return ;
  45. }
  46. if(no<&&act[x][y]==-)
  47. {
  48. printf("-1 -1");
  49. return ;
  50. }
  51. if(act[x][y]==-)
  52. {
  53. w+=;
  54. no-=;
  55. }
  56. else no+=act[x][y];
  57. if(no>=k) no=k;
  58. vis[x][y]=true;
  59. for (R d=;d<;++d)
  60. {
  61. int xx=x+dx[d];
  62. int yy=y+dy[d];
  63. if(xx<||xx>n||yy<||yy>m) continue;
  64. ope[xx][yy]=true;
  65. }
  66. }
  67. printf("%d %d",no,w);
  68. return ;
  69. }

A

  B:https://www.nowcoder.com/acm/contest/179/B

  题意概述:每个数字有一种颜色,连到以$1$为根的一棵树上,每个点的父亲必须是它的一个因数,同一颜色且连在一起的算一个联通块,求通过合理的连边能制造的最多联通块。

  看起来像是个很难的题目,但是其实贪心就行,只要能连到颜色不同的父亲上就连,不能连就连到$1$上即可.复杂度$O(N\sqrt{N})$.更合理的做法是对于每一个数字枚举倍数,运用调和级数计算复杂度$O(NlogN)$

  

  1. # include <cstdio>
  2. # include <iostream>
  3. # include <cstring>
  4. # include <string>
  5. # include <cmath>
  6. # include <algorithm>
  7. # define R register int
  8. # define ll long long
  9.  
  10. using namespace std;
  11.  
  12. const int maxn=;
  13. int n,a[maxn],f[maxn],ans,fa,t;
  14.  
  15. int main()
  16. {
  17. scanf("%d",&n);
  18. ans=;
  19. for (R i=;i<=n;++i)
  20. scanf("%d",&a[i]);
  21. for (R i=;i<=n;++i)
  22. {
  23. fa=;
  24. for (R j=;j*j<=i;++j)
  25. {
  26. if(i%j) continue;
  27. t=j;
  28. if(fa==&&a[t]!=a[i])
  29. f[i]=t,ans++,fa=true;
  30. if(j==) continue;
  31. t=i/j;
  32. if(fa==&&a[t]!=a[i])
  33. f[i]=t,ans++,fa=true;
  34. }
  35. if(!fa) f[i]=;
  36. }
  37. printf("%d",ans);
  38. return ;
  39. }

B

  C:https://www.nowcoder.com/acm/contest/179/C

  题意概述:一个$n$个点$m$条边的无权图,给出多组询问问是否有从$u$到$v$走恰好$l$步的方案数;$n<=100,q<=1000,l<=10^9$

  非常板子的矩阵乘法!然而跑的非常慢,于是首先按照询问的$l$排序,分段进行矩阵乘法.然而...爆零了!为什么?离线做之后一定要记得还原成原来的顺序输出!!!

  改过来也过不了,听说改成倍增+$bitset$就过了.最近牛客网怎么总是出这种有点卡常的题目啊.

  

  1. # include <cstdio>
  2. # include <iostream>
  3. # include <cstring>
  4. # include <string>
  5. # include <cmath>
  6. # include <algorithm>
  7. # define R register int
  8. # define ll long long
  9.  
  10. using namespace std;
  11.  
  12. const int maxn=;
  13. int n,m,u,v,q,l,t[];
  14. struct mat
  15. {
  16. int a[maxn][maxn];
  17. void init()
  18. {
  19. memset(a,,sizeof(a));
  20. for (R i=;i<=n;++i)
  21. a[i][i]=;
  22. }
  23. }a,ans,y;
  24. struct ask
  25. {
  26. int l,u,v,id;
  27. }s[];
  28. bool cmp (ask a,ask b)
  29. {
  30. return a.l<b.l;
  31. }
  32.  
  33. mat mul (mat a,mat b)
  34. {
  35. mat c;
  36. memset(c.a,,sizeof(c.a));
  37. for (R i=;i<=n;++i)
  38. for (R j=;j<=n;++j)
  39. for (R k=;k<=n;++k)
  40. {
  41. if(a.a[i][k]&&b.a[k][j]) c.a[i][j]=;
  42. if(c.a[i][j]) break;
  43. }
  44. return c;
  45. }
  46.  
  47. mat qui (mat a,int b)
  48. {
  49. mat ans;
  50. ans.init();
  51. while(b)
  52. {
  53. if(b&) ans=mul(ans,a);
  54. a=mul(a,a);
  55. b=b>>;
  56. }
  57. return ans;
  58. }
  59.  
  60. inline char gc()
  61. {
  62. static char now[<<],*S,*T;
  63. if (T==S)
  64. {
  65. T=(S=now)+fread(now,,<<,stdin);
  66. if (T==S) return EOF;
  67. }
  68. return *S++;
  69. }
  70. inline int read()
  71. {
  72. R x=;
  73. register char ch=gc();
  74. while(!isdigit(ch))
  75. ch=gc();
  76. while(isdigit(ch)) x=(x<<)+(x<<)+ch-'',ch=gc();
  77. return x;
  78. }
  79.  
  80. int main()
  81. {
  82. n=read(),m=read();
  83. for (R i=;i<=m;++i)
  84. {
  85. u=read(),v=read();
  86. a.a[u][v]=true;
  87. }
  88. y=a;
  89. q=read();
  90. for (R i=;i<=q;++i)
  91. s[i].l=read(),s[i].u=read(),s[i].v=read(),s[i].id=i;
  92. sort(s+,s++q,cmp);
  93. ans.init();
  94. for (R i=;i<=q;++i)
  95. {
  96. int p=s[i].l-s[i-].l;
  97. if(p)
  98. {
  99. a=qui(y,p);
  100. ans=mul(ans,a);
  101. }
  102. if(ans.a[ s[i].u ][ s[i].v ]) t[ s[i].id ]=;
  103. }
  104. for (R i=;i<=q;++i)
  105. if(t[i]) puts("YES");
  106. else puts("NO");
  107. return ;
  108. }

C

  ---shzr

Nowcoder 提高组练习赛-R7的更多相关文章

  1. Nowcoder 提高组练习赛-R1

    https://www.nowcoder.com/acm/contest/172#question 单人报名300元,五人合报免费,于是就和学弟同学学长们组了一个三世同堂的队伍,高一的学长wzhqwq ...

  2. Nowcoder 提高组练习赛-R3

    https://www.nowcoder.com/acm/contest/174#question 今天的题好难呀,只有94个人有分.然后我就爆零光荣 考到一半发现我们班要上物理课,还要去做物理实验( ...

  3. Nowcoder 提高组练习赛-R2

    https://www.nowcoder.com/acm/contest/173#question T1:https://www.nowcoder.com/acm/contest/173/A 题意概述 ...

  4. nowcoder 提高组模拟赛 选择题 解题报告

    选择题 链接: https://www.nowcoder.com/acm/contest/178/B 来源:牛客网 题目描述 有一道选择题,有 \(a,b,c,d\) 四个选项. 现在有 \(n\) ...

  5. nowcoder 提高组模拟赛 最长路 解题报告

    最长路 链接: https://www.nowcoder.com/acm/contest/178/A 来源:牛客网 题目描述 有一张 \(n\) 个点 \(m\) 条边的有向图,每条边上都带有一个字符 ...

  6. nowcoder提高组2题解

    T1 化一下试子就ok code #include<cstdio> #include<algorithm> inline long long read() { long lon ...

  7. 牛客网NOIP赛前集训营-普及组(第二场)和 牛客网NOIP赛前集训营-提高组(第二场)解题报告

    目录 牛客网NOIP赛前集训营-普及组(第二场) A 你好诶加币 B 最后一次 C 选择颜色 D 合法括号序列 牛客网NOIP赛前集训营-提高组(第二场) A 方差 B 分糖果 C 集合划分 牛客网N ...

  8. 刷题总结——mayan游戏(NOIP2011提高组day2T3)

    题目: 题目背景 NOIP2011提高组 DAY1 试题. 题目描述 Mayan puzzle 是最近流行起来的一个游戏.游戏界面是一个 7 行 5 列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即 ...

  9. 刷题总结——飞扬的小鸟(NOIP2014提高组)

    题目: 题目背景 NOIP2014 提高组 Day1 试题. 题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面 ...

随机推荐

  1. js 前端分页空间控件

    现在web注重用户体验与交互性,ajax 提交数据的方式很早就流行了,它能够在不刷新网页的情况下局部刷新数据.前端分页多是用ajax请求数据(其他方式也有比如手动构造表单模拟提交事件等).通过js将查 ...

  2. Jquey节点操作

    创建添加节点: 创建jquery对象:$("<a href="http://baidu.com" target="_blank">百度请点 ...

  3. ASP.NET C# List分页

    List.Skip((pagecount-1)*pagesize).Take(pagesize) 假设你每页10条数据当前是第3页 跳到第4页则:List.Skip((4-1)*10).Take(10 ...

  4. springboot中使用mybatis之mapper

    Spring Boot中使用MyBatis传参方式:使用@Param@Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})& ...

  5. git命令(持续更新)

    将远程仓库中的代码下载到本地仓库:git clone git仓库地址 将本地仓库中修改的文件提交到远程仓库:git push -u origin master 将当前目录添加到本地仓库,.表示当前目录 ...

  6. 简单测试--C#实现中文汉字转拼音首字母

    第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即“最小”的汉字作比较,这里的最小指的是按拼音规则比 ...

  7. SD从零开始33-37

    [原创]SD从零开始33 Billing简介 Billing在SD流程链中的集成: Billing document表征SD流程链中的最后功能: Billing document在R/3系统的不同区域 ...

  8. JSP内置对象——page对象

    观察可发现,这里面的方法,就是Object这个类下的一些方法,下面进行一个简单的演示,比如“toString()”方法: 运行结果: 这时候看到了一个“org.apache.jsp.page_jsp@ ...

  9. 项目报错:Caused by: java.lang.ClassNotFoundException: Didn't find class "..."on path: DexPathList

    项目报错: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.eshore.njb.MyApplicat ...

  10. Android友盟增量更新

    1.增量升级的原理 增量更新的原理就是将本地apk与服务器端最新版本比对,并得到差异包.比如现在的版本是1.1.4,大小是7.2M,新版本是1.1.5.大小是7.3M.我们发现两个版本只有0.1M的差 ...