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

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

 #include <cstdio>
 #include <algorithm>
 using namespace std;
 struct node
 {
     int x;char ch;
 }s[+];
 bool cmp(node& a,node& b)
 {
     return a.x<b.x;
 }
 int main()
 {
     int n;
     while(~scanf("%d",&n))
     {
         getchar();
         ;i<n;i++)
             scanf("%c",&s[i].ch);
         ;i<n;i++)
             scanf("%d",&s[i].x);
         sort(s,s+n,cmp);
         int ans = 0x3f3f3f3f;
         ;i<n;i++)
         {
             ].ch == 'R')
             {
                 ].x)/;
                 ans = min(ans,dis);
             }
         }
         if(ans == 0x3f3f3f3f)
             printf("-1\n");
         else
             printf("%d\n",ans);
     }
     ;
 }

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

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

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

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

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

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

 #include <cstdio>
 #include <cstring>
 #define mem0(x) memset(x,0,sizeof(x))
 ][];
 ],C[];
 int tot,fi,fj,n,m;
 bool judge()
 {
     ;i<=n;i++)
     {
         ;j<=m;j++)
         {
             int cur = R[i] + C[j];
             if(ma[i][j] == '*') cur--;
             if(tot == cur)
             {
                 fi = i, fj = j;
                 return true;
             }

         }
     }
     return false;
 }
 int main()
 {
     while(~scanf("%d%d",&n,&m))
     {
         mem0(R);
         mem0(C);
         ;i<=n;i++)
             scanf();//输入的一个小技巧
         tot = ;
         ;i<=n;i++)
             ;j<=m;j++)
                 if(ma[i][j] == '*')
                 {
                     R[i] ++;
                     C[j] ++;
                     tot++;
                 }
         if(judge())
             printf("YES\n%d %d\n",fi,fj);
         else
             printf("NO\n");
     }
     ;
 }

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

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

 #include <cstdio>
 #include <map>
 #include <queue>
 #include <cstring>
 #include <algorithm>
 #include <iostream>
 using namespace std;
 #define mem0(x) memset(x,0,sizeof(x))
 #define mem1(x) memset(x,-1,sizeof(x))
 typedef long long LL;
 const int INF = 0x3f3f3f3f;

 int a;
 ][];
 int main()
 {
     int n;
     scanf("%d",&n);
     ;i<=n;i++)
     {
         scanf("%d",&a);
         )
         {
             dp[i][] = max(max(dp[i-][], dp[i-][]), dp[i-][]);
         }
         )
         {
             dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
             dp[i][] = max(dp[i-][], dp[i-][]) + ;
         }
         )
         {
             dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
             dp[i][] = max(dp[i-][], dp[i-][]) + ;
         }
         else
         {
             dp[i][] = max(max(dp[i-][],dp[i-][]),dp[i-][]);
             dp[i][] = max(dp[i-][], dp[i-][]) + ;
             dp[i][] = max(dp[i-][], dp[i-][]) + ;
         }
     }
     ;
     ;i<;i++)
         maxn = max(maxn, dp[n][i]);
     printf("%d\n",n-maxn);
     ;
 }

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

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

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

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

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

 #include <cstdio>
 #include <map>
 #include <queue>
 #include <cstring>
 #include <algorithm>
 #include <iostream>
 using namespace std;
 #define mem0(x) memset(x,0,sizeof(x))
 #define mem1(x) memset(x,-1,sizeof(x))
 typedef long long LL;
 const int INF = 0x3f3f3f3f;

 ];
 ];
 int uf_find(int x)
 {
     if(x==pa[x]) return x;
     return pa[x] = uf_find(pa[x]);
 }

 int main()
 {
     int n,cnt,root;
     scanf("%d",&n);
     //uf_init
     ;i<=n;i++) pa[i] = i ;

     cnt = , root = ;
     ;i<=n;i++)
     {
         scanf("%d",&a[i]);
         if(i == a[i])
         {
             cnt++,root = i;
         }
         else
         {
             int fx = uf_find(i);
             int fy = uf_find(a[i]);
             if(fx == fy)   a[i] = i,cnt++;//成环
             else           pa[fx] = fy;
         }
     }
     )
     {
         ;i<=n;i++)
         {
             if(i == pa[i])
             {
                 root = i;
                 break;
             }
         }
         cnt++;
     }
     printf();
     ;i<=n;i++)
     {
         if(i == a[i]) a[i] = root;//根只能有一个
         printf("%d%c",a[i],i==n?'\n':' ');
     }
     ;
 }

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. Typescript Mixins(混合)

    除了惯例的面对对象的思想,另一种较流行的通过可复用组件创建类的方法是将简单的类混合到一起.你可能对这种混合的方式比较熟悉或对Scala语言的特性有理解,这种模式在JavaScript社区也有一定的人气 ...

  2. python3随记——字符编码

    1.1什么是字节 字节(Byte)是计算机信息技术用于计量存储容量的一种计量单位,也表示一些计算机编程语言中的数据类型和语言字符. 比特(bit)在计算机中最小的单位,在二进制位的电脑的系统中,每一b ...

  3. 平面内,线与线 两条线找交点 两条线段的位置关系(相交)判定与交点求解 C#

    个人亲自编写.测试,可以正常使用   道理看原文,这里不多说   网上找到的几篇基本都不能用的   C#代码 bool Equal(float f1, float f2) { return (Math ...

  4. Robots.txt - 禁止爬虫(转)

    Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...

  5. @Controller和@RestController的区别?

    @Controller和@RestController的区别?官方文档:@RestController is a stereotype annotation that combines @Respon ...

  6. Hadoop概括——学习笔记<一>

    之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第一章的笔记 第一章主要讲的是hadoop基础知识.老师讲的还是比较全面简单的,起码作为一个非专业码农以及数据 ...

  7. Form 详细属性--2016年12月4日

    属性       名称 说明   AcceptButton 获取或设置当用户按 Enter 键时所单击的窗体上的按钮.   AccessibilityObject 获取分配给该控件的 Accessib ...

  8. python基础六

    模块 1.定义: 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能),本质就是.py结尾的python文件(文件名:test.py,对应的模块名:test) 包:用来从逻辑上 ...

  9. Json序列化与反序列化

    参考:http://www.cnblogs.com/caofangsheng/p/5687994.html#commentform 下载链接:http://download.csdn.net/deta ...

  10. cookie 巩固

    设定cookie 过期时间: Cookie coke = new Cookie("name", "pattern"); coke.setMaxAge(60);/ ...