因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速

选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很重要的..

E 给出n个城市和m条双向边 把所有的双向边都变成单向的 如果一个城市的入度为0 那它就是孤独的 问有多少个孤独的

想到一个联通分量中 如果没有环(树) 那么肯定有一个点是孤独的 有环就没有了

那就对于每一个未访问的点bfs一下 然后dfs判断有没有环 O(n)的复杂度

F 一个n*m的谷仓与每个格子的高度 给出一个数p 要求对谷仓中的格子进行操作 只能减少它的高度 最后所有的格子要么是高度0 要么是高度x 高度为x的谷仓应该属于同一个联通分量且只有一个 并且至少有一个谷仓的高度没变 最后所有谷仓的高度加起来等于p

nm1000 首先想到了枚举地图 假设这个点是不变的 即这个点高度是x 判断p%x减少耗时 对这个点进行bfs 看满足高度大于等于x且属于一个连通分量的点是否到达p/x个 如果到达 再次bfs选择p/x个 输出

但是这个复杂度最差是n*m*n*m 即有n*m个数字 p为这n*m个数字的lcm cf跑的多快要挂

然而本着交一个证明来过的想法 我加了一个判断p/x与n*m关系的优化 并且修改了vis数组的memset次数 交了一次

发现居然一气跑到107组才t

之后又想到一个优化: 先判断一下当前 如果这个数为x的话 大于等于x的数能否足够p/x

这样就需要一个类似于前缀和的东西 对所有种数字进行记录并排序 记录下来他们的个数 利用代码中xd的累加 这样 cz[x] 表示的就是大于等于x的有多少了

如果不够p/x 就直接continue

不过最后ac了发现一共只有107组数据这种感觉....

E

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<map>
  5. #include<math.h>
  6. #include<iostream>
  7. #include<queue>
  8. using namespace std;
  9. int n , m ;
  10. int a[100050];
  11. int b[100050];
  12. vector<int >q[100050];
  13. int vis[100050];
  14. int bfs(int u){
  15. int cnt = 1;
  16. queue<int >que;
  17. que.push(u);
  18. vis[u] = 1;
  19. while(!que.empty()){
  20. int uu = que.front();que.pop();
  21. for(int i=0;i<q[u].size();i++){
  22. int v = q[u][i];
  23. if(vis[v] == 0){
  24. vis[v] = 1;
  25. cnt ++ ;
  26. que.push(v);
  27. }
  28. }
  29. }
  30. return cnt ;
  31. }
  32. bool dfs(int u, int fa){
  33. vis[u] = 2;
  34. for(int i = 0;i<q[u].size();i++){
  35. int v= q[u][i];
  36. if(v == fa){
  37. continue;
  38. }
  39. if(vis[v] == 2){
  40. return true;
  41. }
  42. vis[v] = 2;
  43. bool ok = dfs(v,u);
  44. if(ok ){
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. int main(){
  51. scanf("%d%d",&n,&m);
  52. for(int i=1;i<=n;i++){
  53. q[i].clear();
  54. }
  55. for(int i=1;i<=m;i++){
  56. int u,v;
  57. scanf("%d%d",&u,&v);
  58. q[u].push_back(v);
  59. q[v].push_back(u);
  60. }
  61. memset(vis,0,sizeof(vis));
  62. int ans = 0;
  63. for(int i=1;i<=n;i++){
  64. if(vis[i] == 0){
  65. int cnt = bfs(i);
  66. bool ok = dfs(i,-1);
  67. if(ok){
  68.  
  69. }
  70. else {
  71. ans ++ ;
  72. }
  73. }
  74. }
  75. printf("%d\n",ans);
  76. }

F

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<map>
  5. #include<math.h>
  6. #include<iostream>
  7. #include<queue>
  8. using namespace std;
  9. #define L long long
  10. L n , m , p;
  11. L a[1050][1050];
  12. L vis[1050][1050];
  13. L b[1050*1050];
  14. int dx[4]= {0,0,1,-1};
  15. int dy[4]= {1,-1,0,0};
  16. bool check(int x,int y)
  17. {
  18. if(x>=1&&x<=n&&y>=1&&y<=m)
  19. {
  20. return true;
  21. }
  22. return false;
  23. }
  24. L bfs(int x,int y,int h,int res)
  25. {
  26. queue<int >q;
  27. q.push(x);
  28. q.push(y);
  29. L cnt = 1;
  30. vis[x][y] = res;
  31. while(!q.empty())
  32. {
  33. int xx = q.front();
  34. q.pop();
  35. int yy = q.front();
  36. q.pop();
  37. for(int i=0; i<4; i++)
  38. {
  39. int xz = xx+ dx[i];
  40. int yz = yy+ dy[i];
  41. if(check(xz,yz))
  42. {
  43. if(vis[xz][yz] != res && a[xz][yz] >= h)
  44. {
  45. vis[xz][yz] = res ;
  46. cnt ++;
  47. q.push(xz);
  48. q.push(yz);
  49. }
  50. }
  51. }
  52. }
  53. return cnt ;
  54. }
  55. void cl(int x,int y,int h,int res,int many)
  56. {
  57. queue<int >q;
  58. q.push(x);
  59. q.push(y);
  60. L cnt = 1;
  61. vis[x][y] = -1;
  62. if(cnt == many)
  63. {
  64. return ;
  65. }
  66. while(!q.empty())
  67. {
  68. int xx = q.front();
  69. q.pop();
  70. int yy = q.front();
  71. q.pop();
  72. for(int i=0; i<4; i++)
  73. {
  74. int xz = xx+ dx[i];
  75. int yz = yy+ dy[i];
  76. if(check(xz,yz))
  77. {
  78. if(vis[xz][yz] == res && a[xz][yz] >= h)
  79. {
  80. vis[xz][yz] = -1 ;
  81. cnt ++;
  82. q.push(xz);
  83. q.push(yz);
  84. if(cnt == many)
  85. {
  86. return ;
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. bool cmp(L a,L b)
  94. {
  95. return a<b;
  96. }
  97. int main()
  98. {
  99. scanf("%lld%lld%lld",&n,&m,&p);
  100. L ma = 0;
  101. map<L , int >cz;
  102. int cnt = 0;
  103. for(int i= 1; i<=n; i++)
  104. {
  105. for(int k=1; k<=m; k++)
  106. {
  107. scanf("%lld",&a[i][k]);
  108. if(ma < a[i][k])
  109. {
  110. ma = a[i][k];
  111. }
  112. if(cz[a[i][k]] == 0)
  113. {
  114. cnt ++;
  115. b[cnt ] = a[i][k];
  116. }
  117. cz[a[i][k]] ++ ;
  118. }
  119. }
  120. L res = 0;
  121. bool ok = false;
  122. memset(vis,0,sizeof(vis));
  123. sort(b+1,b+1+cnt,cmp);
  124. L xd = 0;
  125. for(int i= cnt ; i>=1; i--)
  126. {
  127. cz[b[i]] = cz[b[i]] + xd;
  128. xd = cz[b[i]] ;
  129. }
  130. for(int i=1; i<=cnt ; i++)
  131. {
  132. L h = b[i];
  133. if(p%h != 0)
  134. {
  135. continue;
  136. }
  137. L many = p/h;
  138. if(many > n*m)
  139. {
  140. continue;
  141. }
  142. if(cz[b[i]] < many)
  143. {
  144. continue;
  145. }
  146. res ++ ;
  147. ok = false;
  148. for(int k = 1; k<=n; k++)
  149. {
  150. if(ok)
  151. {
  152. break;
  153. }
  154. for(int j=1; j<=m; j++)
  155. {
  156. if(vis[k][j] != res && a[k][j] == h)
  157. {
  158.  
  159. vis[k][j] = res ;
  160. L many2 = bfs(k,j,h,res);
  161. if(many2 >= many)
  162. {
  163. printf("YES\n");
  164. cl(k,j,h,res,many);
  165. for(int q = 1; q<=n; q++)
  166. {
  167. for(int w = 1; w<=m; w++)
  168. {
  169. if(vis[q][w] == -1)
  170. {
  171. printf("%d",h);
  172. }
  173. else printf("0");
  174.  
  175. if(w == m)
  176. {
  177. printf("\n");
  178. }
  179. else printf(" ");
  180. }
  181. }
  182. ok = true;
  183. break;
  184. }
  185. }
  186. }
  187. }
  188. if(ok )
  189. {
  190. break;
  191. }
  192. }
  193. if(ok == false)
  194. {
  195. printf("NO\n");
  196. }
  197. }

  

Codeforces Round #346 (Div. 2) E F的更多相关文章

  1. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  2. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  3. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs

    F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...

  4. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

  5. Codeforces Round #346 (Div. 2) A Round-House

    A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...

  6. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  7. Codeforces Round #346 (Div. 2) A. Round House 水题

    A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...

  8. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  9. 补题—Codeforces Round #346 (Div. 2) _智商欠费系列

    这次的题目相对容易 但是智商依旧不够用 原因有三点 1.英文水平堪忧 2 逻辑不严密 3 细节掌握不够好 传送门 http://codeforces.com/contest/659 A 题目大意 圆环 ...

随机推荐

  1. wpf,图片灰化处理

    private BitmapSource ToGray(BitmapSource source) { FormatConvertedBitmap re = new FormatConvertedBit ...

  2. struts2总结三:struts2配置文件struts.xml的简单总结

    一.struts中的常量constant的配置. 在struts2中同一个常量的配置有三种方式,第一种在struts.xml中,第二种在struts.properties中配置,第三种在web.xml ...

  3. Codeforces 650B Image Preview(尺取法)

    题目大概说手机有n张照片.通过左滑或者右滑循环切换照片,滑动需要花费a时间:看一张照片要1时间,而看过的可以马上跳过不用花时间,没看过的不能跳过:有些照片要横着看,要花b时间旋转方向.那么问T时间下最 ...

  4. webservice 学习笔记

    1.webservice的概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的 ...

  5. MongoDB 入门之安装篇

    前言:MongoDB 在各 OS 上的安装比较简单,此文章只用来记录,不考虑技术深度. 一.Ubuntu 导入 MongoDB 公钥,添该软件源文件,更新源列表 sudo apt-key adv -- ...

  6. iOS之02-第一个OC的类

    OC是一门面向对象的语言,因此它也有类.对象.静态\动态方法.成员变量的概念.这讲就来创建第一个OC的类. 第一个类的源码: /* 人 类名:Person 属性(成员变量\实例变量):体重.年龄 行为 ...

  7. node.js 实现一个简单的登录拦截器

    拦截器在web开发中随处可见,比如站点的管理后台,不说所有人都能进入,所以就需要做一个拦截器并友好的跳转到提示页. 下面我们简单实现一种,判断用户是否登录成功,登录不成功的用户自动重定向到登录页面. ...

  8. 20145308刘昊阳 《Java程序设计》实验一 Java开发环境的熟悉 实验报告

    20145308刘昊阳 <Java程序设计>实验一报告 实验名称 Java开发环境的熟悉 实验内容 使用JDK编译.运行简单的Java程序 2.使用Eclipse 编辑.编译.运行.调试J ...

  9. ubuntu 安装 Terminator

    sudo apt-get install terminator Ctrl-Shift-E: 垂直分割Ctrl-Shift-O: 水平分割Ctrl-Shift-P: 激活先前的窗口Ctrl-Shift- ...

  10. jquery放大镜效果

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...