A.取中间那个点即可。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[];
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. cin >> a[] >> a[] >> a[];
  10. sort(a,a+);
  11. cout << a[]-a[] << endl;
  12. return ;
  13. }

B.模拟,注意判断是否在括号内。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n;
  5. string s;
  6.  
  7. int main()
  8. {
  9. cin >> n;
  10. getchar();
  11. getline(cin,s);
  12. int maxx = ,cnt = ,now = ,flag = ;
  13. for(int i = ;i < n;i++)
  14. {
  15. if(s[i] == '(')
  16. {
  17. flag = ;
  18. now = ;
  19. }
  20. else if(s[i] == ')')
  21. {
  22. flag = ;
  23. if(now) cnt++;
  24. now = ;
  25. }
  26. else if(s[i] == '_')
  27. {
  28. if(flag == && now) cnt++;
  29. now = ;
  30. }
  31. else
  32. {
  33. now++;
  34. if(flag == ) maxx = max(maxx,now);
  35. }
  36. }
  37. cout << maxx << " " << cnt << endl;
  38. return ;
  39. }

C.先算出ans,再把个数不到ans的数填满。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,m,a[],b[] = {};
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. cin >> n >> m;
  10. for(int i = ;i <= n;i++)
  11. {
  12. cin >> a[i];
  13. if(a[i] <= m) b[a[i]]++;
  14. }
  15. int ans = n/m,cnt = ,now = ;
  16. for(int i = ;i <= n;i++)
  17. {
  18. if(a[i] <= m && b[a[i]] <= ans) continue;
  19. while(b[now] >= ans) now++;
  20. if(now == m+) break;
  21. if(a[i] <= m) b[a[i]]--;
  22. a[i] = now;
  23. b[now]++;
  24. cnt++;
  25. }
  26. cout << ans << " " << cnt << endl;
  27. for(int i = ;i <= n;i++) cout << a[i] << " ";
  28. cout << endl;
  29. return ;
  30. }

D.dfs找出每一个湖泊,按面积排序,把cnt-k个小的填满。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,m,k,vis[][] = {},ok,sum;
  5. int dx[] = {,,-,};
  6. int dy[] = {-,,,};
  7. string s[];
  8. struct xxx
  9. {
  10. int x,y,sum;
  11. friend bool operator <(xxx a,xxx b)
  12. {
  13. return a.sum < b.sum;
  14. }
  15. }a[];
  16.  
  17. void dfs1(int x,int y)
  18. {
  19. if(vis[x][y]) return;
  20. vis[x][y] = ;
  21. sum++;
  22. for(int i = ;i < ;i++)
  23. {
  24. int xx = x+dx[i],yy = y+dy[i];
  25. if(xx < || xx > n || yy < || yy > m)
  26. {
  27. ok = ;
  28. continue;
  29. }
  30. if(s[xx][yy] == '*') continue;
  31. dfs1(xx,yy);
  32. }
  33. }
  34.  
  35. void dfs2(int x,int y)
  36. {
  37. s[x][y] = '*';
  38. for(int i = ;i < ;i++)
  39. {
  40. int xx = x+dx[i],yy = y+dy[i];
  41. if(xx < || xx > n || yy < || yy > m || s[xx][yy] == '*') continue;
  42. dfs2(xx,yy);
  43. }
  44. }
  45. int main()
  46. {
  47. ios::sync_with_stdio(false);
  48. cin >> n >> m >> k;
  49. int cnt = ;
  50. for(int i = ;i <= n;i++)
  51. {
  52. cin >> s[i];
  53. s[i] = " "+s[i];
  54. }
  55. for(int i = ;i <= n;i++)
  56. {
  57. for(int j = ;j <= m;j++)
  58. {
  59. if(s[i][j] == '*' || vis[i][j]) continue;
  60. ok = ;
  61. sum = ;
  62. dfs1(i,j);
  63. if(ok)
  64. {
  65. a[++cnt].x = i;
  66. a[cnt].y = j;
  67. a[cnt].sum = sum;
  68. }
  69. }
  70. }
  71. sort(a+,a++cnt);
  72. cnt -= k;
  73. int ans = ;
  74. for(int i = ;i <= cnt;i++)
  75. {
  76. ans += a[i].sum;
  77. dfs2(a[i].x,a[i].y);
  78. }
  79. cout << ans << endl;
  80. for(int i = ;i <= n;i++)
  81. {
  82. for(int j = ;j <= m;j++) cout << s[i][j];
  83. cout << endl;
  84. }
  85. return ;
  86. }

E.因为是无向图,所以有偶数个度为奇数的点,我们把他们与第n+1个点相连,则所有点的度都是偶数个,存在欧拉回路,输出这个回路的路径(不包括第n+1个点),符合要求。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,m,d[];
  5. set<int> s[];
  6.  
  7. void dfs(int now)
  8. {
  9. while(s[now].size())
  10. {
  11. int t = *s[now].begin();
  12. s[now].erase(t);
  13. s[t].erase(now);
  14. if(now != n+ && t != n+) cout << now << " " << t << endl;
  15. dfs(t);
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. int T;
  22. cin >> T;
  23. while(T--)
  24. {
  25. cin >> n >> m;
  26. memset(d,,sizeof(d));
  27. while(m--)
  28. {
  29. int x,y;
  30. cin >> x >> y;
  31. s[x].insert(y);
  32. s[y].insert(x);
  33. d[x]++;
  34. d[y]++;
  35. }
  36. int ans = ;
  37. for(int i = ;i <= n;i++)
  38. {
  39. if(d[i]%)
  40. {
  41. s[i].insert(n+);
  42. s[n+].insert(i);
  43. }
  44. else ans++;
  45. }
  46. cout << ans << endl;
  47. for(int i = ;i <= n;i++) dfs(i);
  48. }
  49. return ;
  50. }

F.原图无向连通,可以把原图的除s,t外的点分为三类团。

①与s相连。②与t相连。③与s,t相连。

若不存在第③类团,则把相应团与s或t相连,最后把s与t相连。

若存在第③类团,则s与t不必相连,可以通过第③类团来把他们相连,这样其中某个点的度就少了1,为最优情况。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct xx
  5. {
  6. int x,y;
  7. xx(int a,int b):x(a),y(b){};
  8. };
  9. int n,m,x,y,dx,dy,cnt = ,a[] = {},b[] = {},vis[] = {};
  10. vector<int> v[];
  11. vector<xx> ans;
  12.  
  13. void dfs(int now)
  14. {
  15. vis[now] = ;
  16. for(int i = ;i < v[now].size();i++)
  17. {
  18. int t = v[now][i];
  19. if(t == x) a[cnt] = now;
  20. else if(t == y) b[cnt] = now;
  21. else if(!vis[t])
  22. {
  23. ans.push_back(xx(now,t));
  24. dfs(t);
  25. }
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. ios::sync_with_stdio(false);
  32. cin >> n >> m;
  33. for(int i = ;i <= m;i++)
  34. {
  35. cin >> x >> y;
  36. v[x].push_back(y);
  37. v[y].push_back(x);
  38. }
  39. cin >> x >> y >> dx >> dy;
  40. for(int i = ;i <= n;i++)
  41. {
  42. if(vis[i] || i == x || i == y) continue;
  43. ++cnt;
  44. dfs(i);
  45. }
  46. int z = ;
  47. for(int i = ;i <= cnt;i++)
  48. {
  49. if(a[i] == )
  50. {
  51. ans.push_back(xx(b[i],y));
  52. dy--;
  53. }
  54. else if(b[i] == )
  55. {
  56. ans.push_back(xx(a[i],x));
  57. dx--;
  58. }
  59. else z++;
  60. }
  61. if(dx < || dy < || dx+dy- < z)
  62. {
  63. cout << "No" << endl;
  64. return ;
  65. }
  66. if(z == ) ans.push_back(xx(x,y));
  67. else
  68. {
  69. int flag = ;
  70. for(int i = ;i <= cnt;i++)
  71. {
  72. if(a[i] == || b[i] == ) continue;
  73. if(flag)
  74. {
  75. if(dx)
  76. {
  77. ans.push_back(xx(a[i],x));
  78. dx--;
  79. }
  80. else
  81. {
  82. ans.push_back(xx(b[i],y));
  83. dy--;
  84. }
  85. }
  86. else
  87. {
  88. flag = ;
  89. ans.push_back(xx(a[i],x));
  90. dx--;
  91. ans.push_back(xx(b[i],y));
  92. dy--;
  93. }
  94. }
  95. }
  96. cout << "Yes" << endl;
  97. for(int i = ;i < ans.size();i++) cout << ans[i].x << " " << ans[i].y << endl;
  98. return ;
  99. }

Codeforces_723的更多相关文章

随机推荐

  1. ChromeDriver+Selenium安装

    介绍 Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作. ChromeDriver是一个Chrome浏览器驱动,用于驱动Chrome浏览器完成相应的操作 ...

  2. HashMap,HashTable 区别,实现原理。

    HashMap是HashTable 的轻量级,非线程安全的,都是实现了map接口 区别:hashmap 允许空键值对的存在,非线程安全,效率高于hashtable,因为hashtable 是synch ...

  3. docker发布.net core程序的坑

    docker发布遇到的两个问题 1:Could not resolve CoreCLR path. For more details, enable tracing by setting COREHO ...

  4. mongodb学习(二)——基本的数据操作

    数据操作(重点) 数据库的核心--CRUD,增加和删除较为简单,查询和修改较复杂 查询 关系运算符 $gt 大于 $lt 小于 $gte 大于等于 $lte 小于等于 $eq | (key: valu ...

  5. 从操作系统层面理解Linux下的网络IO模型

    I/O( INPUT OUTPUT),包括文件I/O.网络I/O. 计算机世界里的速度鄙视: 内存读数据:纳秒级别. 千兆网卡读数据:微妙级别.1微秒=1000纳秒,网卡比内存慢了千倍. 磁盘读数据: ...

  6. cogs 2450. 距离 树链剖分求LCA最近公共祖先 快速求树上两点距离 详细讲解 带注释!

    2450. 距离 ★★   输入文件:distance.in   输出文件:distance.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 在一个村子里有N个房子,一 ...

  7. max_element( )

    直接用这个函数 , 会比自己写个for 判断快的多了 . position=max_element(a,a+n)-a; position  代表找到最大元素的位置 , max_element( ) 的 ...

  8. fill 的用法

    博客 : http://blog.csdn.net/liuchuo/article/details/52296646 fill函数的作用是:将一个区间的元素都赋予val值.函数参数:fill(vec. ...

  9. 用PHP写下HELLO WORLD!

    一.选择PHP开发工具 1.phpstorm最新版本 2.打开phpstorm界面 按create键,选择new window ,出下如下页面: 鼠标放在文件夹上,右键单击,弹出以下对话框:做如下操作 ...

  10. 盘它!!一步到位,Tensorflow 2的实战 !!LSTM下的股票预测(附详尽代码及数据集)

    关键词:tensorflow2.LSTM.时间序列.股票预测 Tensorflow 2.0发布已经有一段时间了,各种新API的确简单易用,除了官方文档以外能够找到的学习资料也很多,但是大都没有给出实战 ...