A题 http://codeforces.com/problemset/problem/699/A

非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了。

  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. struct node
  5. {
  6. int x;char ch;
  7. }s[+];
  8. bool cmp(node& a,node& b)
  9. {
  10. return a.x<b.x;
  11. }
  12. int main()
  13. {
  14. int n;
  15. while(~scanf("%d",&n))
  16. {
  17. getchar();
  18. ;i<n;i++)
  19. scanf("%c",&s[i].ch);
  20. ;i<n;i++)
  21. scanf("%d",&s[i].x);
  22. sort(s,s+n,cmp);
  23. int ans = 0x3f3f3f3f;
  24. ;i<n;i++)
  25. {
  26. ].ch == 'R')
  27. {
  28. ].x)/;
  29. ans = min(ans,dis);
  30. }
  31. }
  32. if(ans == 0x3f3f3f3f)
  33. printf("-1\n");
  34. else
  35. printf("%d\n",ans);
  36. }
  37. ;
  38. }

B题 http://codeforces.com/problemset/problem/699/B

讲道理 也是水题 然而我在实现的时候 实现不好这个问题 然而梦天2333 毕竟天神啪啪啪随便写写就A了。

这个代码是参考网上的思路搞的,关键是一个V数组和一个C数组记录,行和列的情况。

还有读入字符串的时候要小心的,因为它题目中默认的地图是从1开始的,如果直接scanf ma[i]这样读进来 就是每行都从0开始了,和题意不符

  1. scanf();//输入的一个小技巧

其实思路和它标程是一样的,就是没码出来。

  1. #include <cstdio>
  2. #include <cstring>
  3. #define mem0(x) memset(x,0,sizeof(x))
  4. ][];
  5. ],C[];
  6. int tot,fi,fj,n,m;
  7. bool judge()
  8. {
  9. ;i<=n;i++)
  10. {
  11. ;j<=m;j++)
  12. {
  13. int cur = R[i] + C[j];
  14. if(ma[i][j] == '*') cur--;
  15. if(tot == cur)
  16. {
  17. fi = i, fj = j;
  18. return true;
  19. }
  20.  
  21. }
  22. }
  23. return false;
  24. }
  25. int main()
  26. {
  27. while(~scanf("%d%d",&n,&m))
  28. {
  29. mem0(R);
  30. mem0(C);
  31. ;i<=n;i++)
  32. scanf();//输入的一个小技巧
  33. tot = ;
  34. ;i<=n;i++)
  35. ;j<=m;j++)
  36. if(ma[i][j] == '*')
  37. {
  38. R[i] ++;
  39. C[j] ++;
  40. tot++;
  41. }
  42. if(judge())
  43. printf("YES\n%d %d\n",fi,fj);
  44. else
  45. printf("NO\n");
  46. }
  47. ;
  48. }

C题 http://codeforces.com/problemset/problem/698/A

dp,小心一下 任何一种情况下都是能选择休息的。

  1. #include <cstdio>
  2. #include <map>
  3. #include <queue>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <iostream>
  7. using namespace std;
  8. #define mem0(x) memset(x,0,sizeof(x))
  9. #define mem1(x) memset(x,-1,sizeof(x))
  10. typedef long long LL;
  11. const int INF = 0x3f3f3f3f;
  12.  
  13. int a;
  14. ][];
  15. int main()
  16. {
  17. int n;
  18. scanf("%d",&n);
  19. ;i<=n;i++)
  20. {
  21. scanf("%d",&a);
  22. )
  23. {
  24. dp[i][] = max(max(dp[i-][], dp[i-][]), dp[i-][]);
  25. }
  26. )
  27. {
  28. dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
  29. dp[i][] = max(dp[i-][], dp[i-][]) + ;
  30. }
  31. )
  32. {
  33. dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
  34. dp[i][] = max(dp[i-][], dp[i-][]) + ;
  35. }
  36. else
  37. {
  38. dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
  39. dp[i][] = max(dp[i-][], dp[i-][]) + ;
  40. dp[i][] = max(dp[i-][], dp[i-][]) + ;
  41. }
  42. }
  43. ;
  44. ;i<;i++)
  45. maxn = max(maxn, dp[n][i]);
  46. printf("%d\n",n-maxn);
  47. ;
  48. }

D题 http://codeforces.com/problemset/problem/698/B

这题挺难想的当时。先思考整个问题,无非是由若干个环和若干棵树来组成了最初的图。

如果都是树,那么很好解决,选一棵树作为主树,其他的树根直接链接到主树的根上就解决问题了,修改次数应该是根结点的总数目-1。

如果都是环,那么,把某个环的某个结点接到自己身上,形成一棵树之后,其他的环直接接上来就好了。

如果是环和树都有,那么只要把环接到主树上就好了。

  1. #include <cstdio>
  2. #include <map>
  3. #include <queue>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <iostream>
  7. using namespace std;
  8. #define mem0(x) memset(x,0,sizeof(x))
  9. #define mem1(x) memset(x,-1,sizeof(x))
  10. typedef long long LL;
  11. const int INF = 0x3f3f3f3f;
  12.  
  13. ];
  14. ];
  15. int uf_find(int x)
  16. {
  17. if(x==pa[x]) return x;
  18. return pa[x] = uf_find(pa[x]);
  19. }
  20.  
  21. int main()
  22. {
  23. int n,cnt,root;
  24. scanf("%d",&n);
  25. //uf_init
  26. ;i<=n;i++) pa[i] = i ;
  27.  
  28. cnt = , root = ;
  29. ;i<=n;i++)
  30. {
  31. scanf("%d",&a[i]);
  32. if(i == a[i])
  33. {
  34. cnt++,root = i;
  35. }
  36. else
  37. {
  38. int fx = uf_find(i);
  39. int fy = uf_find(a[i]);
  40. if(fx == fy) a[i] = i,cnt++;//成环
  41. else pa[fx] = fy;
  42. }
  43. }
  44. )
  45. {
  46. ;i<=n;i++)
  47. {
  48. if(i == pa[i])
  49. {
  50. root = i;
  51. break;
  52. }
  53. }
  54. cnt++;
  55. }
  56. printf();
  57. ;i<=n;i++)
  58. {
  59. if(i == a[i]) a[i] = root;//根只能有一个
  60. printf("%d%c",a[i],i==n?'\n':' ');
  61. }
  62. ;
  63. }

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

  1. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  2. Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环

    题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...

  3. Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集

    题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...

  4. Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧

    题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...

  5. Codeforces Round #363 (Div. 2) C. Vacations —— DP

    题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...

  6. Codeforces Round #363 (Div. 2)A-D

    699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include< ...

  7. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  8. Codeforces Round #363 (Div. 2) One Bomb

    One Bomb 题意: 只有一个炸弹,并且一个只能炸一行和一列的'*',问最后能否炸完所以'*',如果可以输出炸弹坐标 题解: 这题做的时候真的没什么好想法,明知道b题应该不难,但只会瞎写,最后越写 ...

  9. Codeforces Round #363 (Div. 2)->C. Vacations

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. bzoj 1004 Cards

    1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...

  2. JAVA起名规范

    1:包名 package com.cenzhongman.模块名.组件 必须全部小写,作为java文件第一行代码 2:类名 名词,表示一类实物,如:人类 首字母大写 3.接口名 形容词/副词,表示一种 ...

  3. Python之路【第十九篇】自定义分页实现(模块化)

    自定义分页 1.目的&环境准备 目的把分页写成一个模块的方式然后在需要分页的地方直接调用模块就行了. 环境准备Django中生成一个APP并且注册,配置URL&Views 配置URL ...

  4. 大熊君JavaScript插件化开发------(实战篇之DXJ UI ------ Tab功能扩展完结版)

    一,开篇分析 Hi,大家好!大熊君又和大家见面了,还记得上一篇文章吗.主要讲述了一个“Tab”插件是如何组织代码以及实现的”,以及过程化设计与面向对象思想设计相结合的方式是 如何设计一个插件的,两种方 ...

  5. Pandas-数据整理

    Pandas包对数据的常用整理功能,相当于数据预处理(不包括特征工程) 目录 丢弃值 drop() 缺失值处理 isnull() & notnull() dropna() fillna() 值 ...

  6. MySQL提示:The server quit without updating PID file问题的解决办法(转载)

    MySQL提示:The server quit without updating PID file问题的解决办法 今天网站web页面提交内容到数据库,发现出错了,一直提交不了,数找了下原因,发现数据写 ...

  7. width的数值为百分比

    对于width的数值为百分比的时候,表示该元素的长度是相对于父容器来算的. 对于padding-right和padding-left比较好理解也是相对于父容器来算的,但容易出错的是padding-to ...

  8. PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令

    exec 或者 system 都可以调用cmd 的命令 直接上代码: <?php /** 打开windows的计算器 */ exec('start C:WindowsSystem32calc.e ...

  9. MapReduce的核心资料索引 [转]

    转自http://prinx.blog.163.com/blog/static/190115275201211128513868/和http://www.cnblogs.com/jie46583173 ...

  10. (原)android的alertdialog中加入edittext但是不弹出软键盘等问题的解决与原因

    摘要:alertdialog中加入edittext但是不弹出软键盘等问题网上有很多不管用的解决方案, 本文意在给出更有效的解决办法,并初步探究其原因 正文 在对话框中插入文本框是十分常见的需求 通常我 ...