A.把右上角的凹缺口补上变成凸的就成了规则矩形

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. int main(){
  45. LL w1,h1,w2,h2;
  46. scanf("%lld%lld%lld%lld",&w1,&h1,&w2,&h2);
  47. LL ans = w1 + w1 + h1 + h1 + h2 + h2 + ;
  48. Prl(ans);
  49. return ;
  50. }

A

B.画在图上就是两条斜线之间有多少可以水平的线,显然是下面这条线的最高点和上面这条线的最低点作差,记得打一个vis标记记录哪些线取过了

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. int main(){
  45. Sca(N);
  46. LL la = ,lb = ;
  47. LL ans = ;
  48. LL now = ;
  49. for(int i = ; i <= N ; i ++){
  50. LL a,b; scanf("%lld%lld",&a,&b);
  51. int t = max(max(la,lb),now);
  52. if(min(a,b) >= t){
  53. ans += min(a,b) - t + ;
  54. now = min(a,b) + ;
  55. }
  56. la = a; lb = b;
  57. }
  58. Prl(ans);
  59. return ;
  60. }

B

C.开始觉得要二分,后来觉得要O(n3),仔细一看发现O(n)

显然取两条非递减的线,从最高点往两边降低,贪心的发现每次都升高最高点更低的那个路径就可以了。

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. int a[maxn];
  45. int b[maxn],c[maxn];
  46. int main(){
  47. Sca(N);
  48. for(int i = ; i <= N ; i ++) Sca(a[i]);
  49. sort(a + ,a + + N);
  50. int cnt1 = ,cnt2 = ;
  51. b[++cnt1] = a[];
  52. c[++cnt2] = a[];
  53. for(int i = ; i <= N ; i ++){
  54. if(b[cnt1] < c[cnt2]) b[++cnt1] = a[i];
  55. else c[++cnt2] = a[i];
  56. }
  57. for(int i = ; i <= cnt1; i ++) printf("%d ",b[i]);
  58. for(int i = cnt2; i >= ; i --) printf("%d ",c[i]);
  59. return ;
  60. }

C

D.拓扑排序例题。

先把所有的等于号用并查集合并,找大小之间的冲突。然后用拓扑排序标记顺便判环。

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. char MAP[maxn][maxn];
  45. struct Edge{
  46. int to,next;
  47. }edge[maxn * maxn * ];
  48. int fa[maxn * ],tot,head[maxn * ],ind[maxn * ];
  49. void init(){
  50. for(int i = ; i <= N + M; i ++){
  51. head[i] = -;
  52. fa[i] = i;
  53. ind[i] = ;
  54. }
  55. tot = ;
  56. }
  57. void add(int u,int v){
  58. edge[tot].to = v;
  59. edge[tot].next = head[u];
  60. head[u] = tot++;
  61. }
  62. int find(int x){
  63. if(x == fa[x]) return x;
  64. return fa[x] = find(fa[x]);
  65. }
  66. void Union(int a,int b){
  67. a = find(a); b = find(b);
  68. fa[a] = b;
  69. }
  70. int ans[maxn];
  71. int main(){
  72. Sca2(N,M); init();
  73. bool flag = ;
  74. for(int i = ; i <= N ; i ++){
  75. scanf("%s",MAP[i] + );
  76. for(int j = ; j <= M ; j ++){
  77. if(MAP[i][j] == '='){
  78. Union(i,j + N);
  79. }
  80. }
  81. }
  82. for(int i = ; i <= N && flag; i ++){
  83. for(int j = ; j <= M ; j ++){
  84. if(MAP[i][j] == '=') continue;
  85. int a = find(i),b = find(j + N);
  86. if(a == b){
  87. flag = ;
  88. break;
  89. }
  90. if(MAP[i][j] == '>'){
  91. add(b,a); ind[a]++;
  92. }else{
  93. add(a,b); ind[b]++;
  94. }
  95. }
  96. }
  97. if(!flag){
  98. puts("No");
  99. return ;
  100. }
  101. queue<int>Q;
  102. for(int i = ; i <= N + M; i ++){
  103. if(find(i) == i && !ind[i]){
  104. ans[i] = ;
  105. Q.push(i);
  106. }
  107. }
  108. while(!Q.empty()){
  109. int u = Q.front(); Q.pop();
  110. for(int i = head[u]; ~i; i = edge[i].next){
  111. int v = edge[i].to;
  112. ans[v] = max(ans[v],ans[u] + );
  113. ind[v]--;
  114. if(!ind[v]) Q.push(v);
  115. }
  116. }
  117. for(int i = ; i <= N + M; i ++){
  118. if(fa[i] == i && ind[i]) flag = ;
  119. }
  120. if(!flag){
  121. puts("No");
  122. return ;
  123. }
  124. puts("Yes");
  125. for(int i = ; i <= N ; i ++){
  126. printf("%d ",ans[find(i)]);
  127. }
  128. puts("");
  129. for(int j = N + ; j <= N + M; j ++){
  130. printf("%d ",ans[find(j)]);
  131. }
  132. return ;
  133. }

D

E.dp[100000][30]记录到i这个字符串j的最长长度。

如果右边的字符串都为k,那么dp[i][j] = max(dp[i][j],len * (dp[i - 1][j] + 1) + dp[i - 1][j]);

否则字符就变为前后缀与他相同的最长长度相加

如果曾经出现过这个字符,这个字符的出现次数至少为1

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = 1e5 + ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. LL ans[];
  45. LL dp[maxn][];
  46. LL pre[];
  47. LL tmp[];
  48. char str[];
  49. int main(){
  50. Sca(N);
  51. for(int i = ; i <= N ; i ++){
  52. scanf("%s",str);
  53. LL len = strlen(str);
  54. LL a = ,b = len;
  55. for(int j = ; j < ; j ++) tmp[j] = ;
  56. for(int j = ; j < len; j ++){
  57. if(j && str[j - ] == str[j]) pre[j] = pre[j - ] + ;
  58. else pre[j] = ;
  59. tmp[str[j] - 'a'] = max(tmp[str[j] - 'a'],pre[j]);
  60. }
  61. for(int j = ; j < ; j ++){
  62. dp[i][j] = tmp[j];
  63. int l = ,r = len - ;
  64. while(l <= r && str[l] == j + 'a') l++;
  65. while(r > l && j + 'a' == str[r]) r--;
  66. if(l == len){
  67. dp[i][j] = max(dp[i][j],len * (dp[i - ][j] + ) + dp[i - ][j]);
  68. }else if(dp[i - ][j]){
  69. dp[i][j] = max(dp[i][j],l + len - r);
  70. }
  71. }
  72. }
  73. LL sum = ;
  74. for(int j = ; j < ; j ++) sum = max(sum,dp[N][j]);
  75. Prl(sum);
  76. return ;
  77. }

E

F.喜闻乐见的送分F题,开到就是赚到。

并查集模板题,加一个l[maxn],r[maxn]表示这个集合最左最右的数字

nxt[maxn]表示这个数字的下一个数字,每次匹配u,v都把u集合放在v集合的左边,更新一下几个数组

  1. #include <map>
  2. #include <set>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17. #define For(i, x, y) for(int i=x;i<=y;i++)
  18. #define _For(i, x, y) for(int i=x;i>=y;i--)
  19. #define Mem(f, x) memset(f,x,sizeof(f))
  20. #define Sca(x) scanf("%d", &x)
  21. #define Sca2(x,y) scanf("%d%d",&x,&y)
  22. #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define Scl(x) scanf("%lld",&x);
  24. #define Pri(x) printf("%d\n", x)
  25. #define Prl(x) printf("%lld\n",x);
  26. #define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define mp make_pair
  30. #define PII pair<int,int>
  31. #define PIL pair<int,long long>
  32. #define PLL pair<long long,long long>
  33. #define pb push_back
  34. #define fi first
  35. #define se second
  36. typedef vector<int> VI;
  37. int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
  38. while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
  39. const double eps = 1e-;
  40. const int maxn = ;
  41. const int INF = 0x3f3f3f3f;
  42. const int mod = 1e9 + ;
  43. int N,M,K;
  44. int fa[maxn],r[maxn],l[maxn];
  45. int nxt[maxn];
  46. void init(){
  47. for(int i = ; i <= N ; i ++){
  48. fa[i] = r[i] = l[i] = i;
  49. nxt[i] = -;
  50. }
  51. }
  52. int find(int x){
  53. if(x == fa[x]) return x;
  54. return fa[x] = find(fa[x]);
  55. }
  56. int main(){
  57. Sca(N); init();
  58. for(int i = ; i <= N - ; i ++){
  59. int u,v; Sca2(u,v);
  60. u = find(u); v = find(v);
  61. nxt[r[u]] = l[v];
  62. l[v] = l[u];
  63. fa[u] = v;
  64. }
  65. int root = l[find()];
  66. for(int i = ; i <= N ; i ++){
  67. printf("%d ",root);
  68. root = nxt[root];
  69. }
  70. return ;
  71. }

F

codeforces-1131 (div2)的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. Codeforces 1131 (div 2)

    链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  10. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. [C#学习笔记1]用csc.exe和记事本写一个C#应用程序

    csc.exe是C#的命令行编译器(CSharpCompiler),可以编译C#源程序成可执行程序.它与Visual Studio等IDE(Integrated Development Environ ...

  2. C# 利用键值对取代Switch...Case语句

    swich....case 条件分支多了之后,会严重的破坏程序的美观性. 比如这个 上述代码是用于两个进程之间通信的代码,由于通信的枚举特别的多,所以case的分支特别的多.导致了代码的可读性,可维护 ...

  3. 章节十、4-CSS Classes---用多个CSS Classes定位元素

    以下演示操作以该网址中的输入框为例:https://learn.letskodeit.com/p/practice 一.使用input[class=inputs]验证元素是否唯一 注意:使用“clas ...

  4. 【转】Python之道

    作者:Vamei 出处:http://www.cnblogs.com/vamei Python有一个彩蛋,用下面语句调出: import this 该彩蛋的文档记录于PEP 20. 语句执行之后,终端 ...

  5. 标识符and数据类型

    一,标识符 1.标识符用来给类,变量,包,方法等起名字的. 2.只能由字符,下滑线,美元符组成:这里的字符有大小写字母,中文字符,数字字符,但是符号只能有两个下划线和美元符. 3.不能由数字开头. 4 ...

  6. jpa使用过程中出现问题记录[持续更新]

    1.自定义JPQL语句,出现Not supported for DML operations 错误. 解决方案:在@Query注解上面加上@Modifying注解. //出现问题的代码 @Query( ...

  7. easyui validatebox textbox 取值和赋值

    总结:表单元素使用easyui时,textbox和validatebox设置值和获取值的方式不一样 text-box设置值只能使用id选择器选择表单元素,只能使用textbox("setVa ...

  8. WordPress慢的八种解决方法(用排查法解决)

    WordPress的打开速度慢会影响到用户体验和关键词的稳定排名,WordPress为什么加载慢呢?其实很简单的,就是WordPress水土不服,用WordPress的大家都知道,WordPress是 ...

  9. CRM销售人员针对的客户的权重分配的思想

    巧妙使用权重http://www.ziawang.com/article/52/ Django 项目CRM总结 - Pythia丶陌乐 - 博客园https://www.cnblogs.com/sup ...

  10. MySQL select into outfile 和 load data infile数据跨库转移

    select into outfile用法 SELECT ... FROM TABLE_A INTO OUTFILE "/path/to/file" FIELDS TERMINAT ...