782C. Andryusha and Colored Balloons DFS】的更多相关文章

Link 题意: 给出一棵树,要求为其染色,并且使任意节点都不与距离2以下的节点颜色相同 思路: 直接DFS.由某节点出发的DFS序列,对于其个儿子的cnt数+1,那么因为DFS遍历的性质可保证兄弟结点的颜色不同,只需考虑当前节点是否与父亲结点和父亲的父亲结点颜色是否相同. /** @Date : 2017-05-09 22:37:25 * @FileName: 782C DFS.cpp * @Platform: Windows * @Author : Lweleth (SoundEarlf@g…
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he…
C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he…
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha goes through a park each day. The squares and…
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! 题目链接:codeforces781A Andryusha and Colored Balloons 正解:构造+结论 解题报告: 考虑答案显然是$max(度数)+1$,这个似乎很好想,对于每个点我需要保证与之相邻的所有点颜色互不相同且与自己不同,那么需要…
C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 200005 ],V[maxn<<],dis[maxn],ans; void dfs(int now,int fa) { ; for…
C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he…
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable…
从任意点出发,贪心染色即可. #include<cstdio> #include<algorithm> using namespace std; int v[200010<<1],next[200010<<1],first[200010],e; void AddEdge(int U,int V) { v[++e]=V; next[e]=first[U]; first[U]=e; } bool vis[200010]; int n,col[200010]; v…
[题目链接]:http://codeforces.com/contest/782/problem/C [题意] 给你一棵树 让你满足要求 ->任意相连的3个节点的颜色不能相同 的情况下进行染色 问最少需要的颜色数目 [题解] 这种染色题一般只要贪心染就好了 即之前没出现过的颜色最小的颜色就好; (这里的之前指的是当前枚举的节点和它的父亲节点以及这个节点的儿子节点们..) 感觉很多题都要顺着题意去做啊; [完整代码] #include <bits/stdc++.h> using names…
http://codeforces.com/contest/782/problem/C 题意:给一棵树染最少的颜色,使得相邻距离为2的点都是不同的颜色,问最少是多少种颜色并输出每个点的颜色. 思路:比赛的时候没想到是找度最大的一个点并+1就是总颜色数,一直想怎么构造. 最后的总颜色数是度最大的一个点的度数+1.因为我们选的这个点到儿子的距离为1,因此其某一个儿子到另一个儿子的距离为2,就是这些儿子都要染成不同的颜色,+1是因为自己本身也要是不同的颜色. 然后确定了总颜色数,就可以DFS染色了.…
题意: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reacha…
前言 完了,完了,咕值要没了,赶紧写题解QAQ. 题意简述 给相邻的三个节点颜色不能相同的树染色所需的最小颜色数. 题解 这道题目很显然可以用深搜. 考虑题目的限制,如果当前搜索到的点为u, 显然u的父亲节点,u本身和u的所有儿子不能同色(因为兄弟之间相差为2). 由于DFS解题,所以搜索到u时,u本身和u的父亲肯定已经有颜色了,那么现在要结局的使u的所有儿子的颜色,那么根据贪心的思想对于每个u的儿子,颜色能往小取就往小取,在选取颜色的时候应当注意,选取的颜色不能与u和u的父亲节点的颜色相同.…
看来快掉到灰名的蒟蒻涨rating也快... A题模拟一下就好(一开始还sb,, #include<bits/stdc++.h> #define LL long long using namespace std; ]; ],n; int main() { scanf("%d",&n); ; i<=*n; i++) { int x; scanf("%d",&x); ; else tot--; ans=max(ans,tot); } c…
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2248 题意:(1)求图中四连块(有公共边的方块)的个数: (2)求图中八连块(有公共顶点的方块)的个数. #include<stdio.h> #include<string.h> ; int vis1[N][N],map[N][N],vis[N][N]; void dfs1(int x,int y)//搜索四个方向 { if (!…
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the…
B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates…
C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he…
题解:n个气球 从1到n染色,如果a.b和c是不同的正方形,a和b在它们之间有一条直接的路径,b和c之间有一条直接的路径,然后在这三个方块上的气球颜色是不同的. AC代码 #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algo…
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放学我呆到十点然后还要跑回家耽误时间....要不然$D$题就写完了 周末一些成绩好的同学单独在艺术楼上课然后晚上下第一节晚自习和他们在回廊里玩开灯之后再关上一片漆黑真好玩 A.Andryusha and Socks 日常煞笔提.....我竟然$WA$了一次忘了$n<<1$ #include <…
Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Meeting Place Cannot Be Changed 题目大意:n个人,第i个人位于xi,速度为vi,找到一个点使得所有人到这个点的耗时最小,输出耗时.(n<=60000) 思路:二分答案,知道耗时后可以求出每个人能到达的区间,如果所有区间有交则合法,复杂度O(nlog). #include<…
唉,昨天晚上迷迷糊糊地去打cf,结果fst两题,掉回蓝了... A.Andryusha and Colored Balloons 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色数和染色方案. n<=2*10^5 题解:求一个度数最大的点,度数+1即是颜色数,然后暴力染色. #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #includ…
                                                                                         C. Andryusha and Colored Balloons   Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorat…
精神不佳,选择了在场外同步划水 没想到实际做起来手感还好,早知道就报名了…… 该打 未完待续233 A. Andryusha and Socks 模拟,模拟大法好.注意每次是先判断完能不能收进柜子,再算桌子上的袜子数量的. /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> using na…
紫书例题p245 Piotr found a magical box in heaven. Its magic power is that if you place any red balloon inside it then, after one hour, it will multiply to form 3 red and 1 blue colored balloons. Then in the next hour, each of the red balloons will multip…
pic[][]数组存储每个点的值,0或1,输入时在原图的周围加了一圈0. color[][]数组存储每个点的color值,从1开始,dfs(row, col, c) 负责对每个点着色,连通在一起的连通块的颜色相同. 因为最先着色的是最外围的白色点,即background white,这些点的color值是1. neighbour[]数组的下标是color值,内容是一个set,存储下标color所代表的连通块周围的连通块的颜色,background white这个连通块不算. 比如 1. 测试用例…
Piotr found a magical box in heaven. Its magic power is that if you place any red balloon inside it then, after one hour, it will multiply to form 3 red and 1 blue colored balloons. Then in the next hour, each of the red balloons will multiply in the…
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.They were very interested about this event, an…
Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's Day, there will be a game named "crashing balloon" on TV.   The rule is very simple.  On the ground there are 100 labeled balloons, with the num…
Balloons Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image. They were very interested about…