A. The New Year: Meeting Friends


  1. #include <set>
  2. #include <map>
  3. #include <stack>
  4. #include <queue>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <algorithm>
  10. using namespace std;
  11. typedef long long LL;
  12. #define mem(x,y) memset(x, y, sizeof(x))
  13. #define lson l,m,rt << 1
  14. #define rson m+1,r,rt << 1 | 1
  15. ? a : gcd(b, a % b);}
  16. int lcm(int a, int b){return a / gcd(a, b) * b;}
  17.  
  18. int main()
  19. {
  20. ];
  21. scanf(], &a[], &a[]);
  22. sort(a, a + );
  23. printf(] - a[]);
  24. ;
  25. }

B - Text Document Analysis

题意:此题是一道字符串题目,统计括号内的单词个数以及括号外最长的单词长度。

字符串的题目漏了考虑'\n'的结尾!!!

  1. #include <set>
  2. #include <map>
  3. #include <stack>
  4. #include <queue>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <algorithm>
  10. using namespace std;
  11. typedef long long LL;
  12. #define mem(x,y) memset(x, y, sizeof(x))
  13. #define lson l,m,rt << 1
  14. #define rson m+1,r,rt << 1 | 1
  15. ? a : gcd(b, a % b);}
  16. int lcm(int a, int b){return a / gcd(a, b) * b;}
  17.  
  18. ];
  19. int main()
  20. {
  21. int len;
  22. scanf("%d", &len);
  23. scanf("%s", s);
  24. , len_in = , len_out = , num_in = ,len_max = ;
  25. ; i < len; i++)
  26. {
  27. if(s[i] == '(')
  28. {
  29. flag1 = ;
  30. len_max = max(len_max, len_out);
  31. len_out = ;
  32. continue;
  33. }
  34. if(flag1)
  35. {
  36. if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z') )
  37. len_in++;
  38. else if(s[i] == '_')
  39. {
  40. if(len_in) num_in++;
  41. len_in = ;
  42. }
  43. else if(s[i] == ')')
  44. {
  45. flag1 = ;
  46. if(len_in) num_in++;
  47. len_in = ;
  48. }
  49. }
  50. else
  51. {
  52. if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z') )
  53. len_out++;
  54. else if(s[i] == '_')
  55. {
  56. len_max = max(len_max, len_out);
  57. len_out = ;
  58. }
  59. }
  60. }
  61. len_max = max(len_max, len_out);
  62. printf("%d %d\n", len_max, num_in);
  63. ;
  64. }

其实写复杂了,hhhhh。别人的

  1. #include<cstdio>
  2. #include <cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<vector>
  7. #include <map>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. ,len=,max=,num=;
  13. ];
  14. scanf("%d",&n);
  15. scanf("%s",ch);
  16. ;i==||ch[i-]!='\0';i++)
  17. {
  18. if(ch[i]=='_'||ch[i]=='('||ch[i]==')'||ch[i]=='\0')
  19. {
  20. &&max<len)
  21. {
  22. max=len;
  23. }
  24. &&len!=)
  25. {
  26. num++;
  27. }
  28. len=;
  29. if(ch[i]=='(')
  30. {
  31. flag=;
  32. }
  33. else if(ch[i]==')')
  34. {
  35. flag=;
  36. }
  37. }
  38. else
  39. {
  40. len++;
  41. }
  42. }
  43. printf("%d %d",max,num);
  44. ;
  45. }

C - Polycarp at the Radio

这题意太迷了。读不懂。

D - Lakes in Berland

题意:n*m的图里,‘.’为湖,‘*’为陆地,'.'在边界的是与大海相连(即不为湖),上下左右相连的为同一个湖或者同一片海,现在要求只留下k个湖,问要最少填多少个格子。

直接贪心+dfs就A了。

  1. #include <set>
  2. #include <map>
  3. #include <stack>
  4. #include <queue>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <algorithm>
  10. using namespace std;
  11. typedef long long LL;
  12. #define mem(x,y) memset(x, y, sizeof(x))
  13. #define lson l,m,rt << 1
  14. #define rson m+1,r,rt << 1 | 1
  15. ? a : gcd(b, a % b);}
  16. int lcm(int a, int b){return a / gcd(a, b) * b;}
  17.  
  18. int n, m, k, ans, flag;
  19. ][];
  20. ][];
  21. , , , -};
  22. , -, , };
  23. #define judge(x, y) 0 <= x && x < n && 0 <= y && y < m && vis[x][y] == 0
  24.  
  25. struct node
  26. {
  27. int x, y, s;
  28. node(int xx, int yy, int ss){x = xx, y = yy, s = ss;}
  29. bool operator < (const node& other)const
  30. {
  31. return s > other.s;
  32. }
  33. };
  34. int dfs(int x, int y, int id)
  35. {
  36. ;
  37. ;
  38. vis[x][y] = ;
  39. || x == n - || y == || y == m - ) flag = ;
  40. && ma[x][y] == '.')
  41. {
  42. ma[x][y] = '*', ans++;
  43. }
  44.  
  45. ; i < ; i++)
  46. {
  47. int fx = x + dx[i], fy = y + dy[i];
  48. if(judge(fx, fy) && ma[fx][fy] == '.')
  49. {
  50. s += dfs(fx, fy, id);
  51. }
  52. }
  53. return s;
  54. }
  55.  
  56. int main()
  57. {
  58. scanf("%d%d%d", &n, &m, &k);
  59. ; i < n; i++)
  60. {
  61. scanf("%s", ma[i]);
  62. }
  63. priority_queue<node>que;
  64. ; i < n; i++)
  65. {
  66. ; j < m; j++)
  67. {
  68. && ma[i][j] == '.')
  69. {
  70. flag = ;
  71. );
  72. if(t && flag) que.push(node(i, j, t));
  73. }
  74.  
  75. }
  76. }
  77. mem(vis, );
  78. ans = ;
  79.  
  80. while(que.size() > k)
  81. {
  82. node cur = que.top();que.pop();
  83. dfs(cur.x, cur.y, );
  84. }
  85.  
  86. printf("%d\n", ans);
  87. ; i < n; i++)
  88. printf("%s\n", ma[i]);
  89. ;
  90. }

E. One-Way Reform(欧拉路径)

题意:
给你一个n个点m条边的无向连通图,没有自环没有重边(图论题一定一定要记得考虑有没有自环和重边) ,然后让你给每条边规定方向,希望使得尽可能多的点拥有相同的入度与出度,让你输出满足这个条件的最大点数和每条边最后的定向。

题解:你想吧,一个连通图,如果存在奇数的度数的顶点,那么它的个数一定是偶数个,因为你想啊,连通图吧,度数=边数*2肯定是偶数,对吧。所以奇数度的顶点也一定是偶数个。那么把所有度数为奇数的顶点和一个新增顶点相连,则图上所有顶点的度数就都是偶数了,构成欧拉图,然后欧拉路径。ans数组记录路径。

  1. #include <set>
  2. #include <map>
  3. #include <stack>
  4. #include <queue>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <algorithm>
  10. using namespace std;
  11. typedef long long LL;
  12. #define mem(x,y) memset(x, y, sizeof(x))
  13. #define lson l,m,rt << 1
  14. #define rson m+1,r,rt << 1 | 1
  15. ? a : gcd(b, a % b);}
  16. int lcm(int a, int b){return a / gcd(a, b) * b;}
  17.  
  18. int T, V, E;
  19. + ;
  20. set<int>s[maxn_v];
  21. vector<pair<int, int> >ans;
  22. void init()
  23. {
  24. ; i <= V; i++)
  25. s[i].clear();
  26. ans.clear();
  27. }
  28. void dfs(int u)
  29. {
  30. while(s[u].size())
  31. {
  32. int v = *s[u].begin();
  33. s[u].erase(v);
  34. s[v].erase(u);
  35. ans.push_back(make_pair(u, v));
  36. dfs(v);
  37. }
  38. }
  39. int main()
  40. {
  41. scanf("%d", &T);
  42. while(T--)
  43. {
  44. init();
  45. scanf("%d%d", &V, &E);
  46. ; i < E; i++)
  47. {
  48. int u, v;
  49. scanf("%d%d", &u, &v);
  50. s[u].insert(v);
  51. s[v].insert(u);
  52. }
  53. ; i <= V; i++)
  54. {
  55. )
  56. {
  57. s[i].insert(V + );
  58. s[V + ].insert(i);
  59. }
  60. }
  61. printf(].size());
  62. ; i <= V; i++)
  63. dfs(i);
  64. ; i < ans.size(); i++)
  65. {
  66. && ans[i].second != V + )
  67. printf("%d %d\n", ans[i].first, ans[i].second);
  68. }
  69.  
  70. }
  71. ;
  72. }

F. st-Spanning Tree

题意:给你一个n个顶点,m个条边的无向联通图,没有自环没有重边,给你两个顶点,和两个值,让你搞出任意一个生成树,使得两个顶点的度数,分别不超过这两个值。

Codeforces Round #375 (Div. 2)的更多相关文章

  1. Codeforces Round #375 (Div. 2) - D

    题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...

  2. Codeforces Round #375 (Div. 2) - C

    题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...

  3. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  4. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  5. Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树

    F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...

  6. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  7. Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心

    D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...

  8. Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟

    B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...

  9. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  10. Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心

    http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...

随机推荐

  1. Java实现的二分查找算法

    二分查找又称折半查找,它是一种效率较高的查找方法. 折半查找的算法思想是将数列按有序化(递增或递减)排列,查找过程中采用跳跃式方式查找,即先以有序数列的中点位置为比较对象,如果要找的元素值小 于该中点 ...

  2. Brackets前端开发IDE工具

    Brackets是一个开源的前端开发IDE工具,网页设计师和前端开发人员必备的前端开发IDE工具. 它能够使你在开发WEB网站实时预览你的网页,目前版本只适用于Chrome浏览器可以实时预览效果 支持 ...

  3. 关于学习angularJS 的一些心得

    从一开始接触到 angularJS 的时候,一头雾水啊. 下面根据学习资料,主要来 阐述一点,关于angularJS学习中需要注意的点 1.angularJS 是可以做到MVC 模式 2.angula ...

  4. [Python] 网络爬虫和正则表达式学习总结

    以前在学校做科研都是直接利用网上共享的一些数据,就像我们经常说的dataset.beachmark等等.但是,对于实际的工业需求来说,爬取网络的数据是必须的并且是首要的.最近在国内一家互联网公司实习, ...

  5. eclipse version

    查看Eclipse的版本号: 1. 找到eclipse安装目录 2. 进入readme文件夹,打开readme_eclipse.html 3. readme_eclipse.html呈现的第二行即数字 ...

  6. no screens found! ubuntu进不了图形界面了

    no screens found! ubuntu进不了图形界面了 结果是没装显卡 startx error. reinstall xorg, x server doesn't work. driver ...

  7. IIS相关知识

    1.在web.config中,iis6使用<system.web>下配置项,iis7使用<system.webServer>下配置项 2.<httpHandlers> ...

  8. swift 001

    swift 001  = 赋值是没有返回值的 所以 int a=10; int b=20; if(a=b){ printf("这个是错误的"); } swift  中的模运算 是支 ...

  9. Qt:正则表达式语法:

         正则表达式是验证输入.从输入中提取数据以及对输入进行搜索和替换的强大工具,所谓正则表达式,regexp是一种利用模式匹配语言来描述字符串组成限制条件的方式;        Qt 提供了一个Q ...

  10. Python网络编程之线程,进程

    一. 线程: 基本使用 线程锁 线程池 队列(生产者消费者模型) 二. 进程:  基本使用  进程锁 进程池 进程数据共享 三. 协程: gevent greenlet 四. 缓存: memcache ...