CF 272E Dima and Horses 染色,dfs 难度:2】的更多相关文章

http://codeforces.com/problemset/problem/272/E 把仇恨关系想象为边, 因为度只能为0,1,2,3,所以有以下几种 0,1 直接放即可 2: 有(1,1),(0,2)两种情况,第一种随便放,第二种放0那里 3:有(1,2),(0,3)两种情况,第一种放1,第二种放0那里 也就是说,怎样都有解 dfs寻找即可 不过一开始觉得这样不靠谱,因为时间复杂度很高,不过没想到过了 #include <cstdio> #include <vector>…
E. Dima and Horses Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is…
http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,m; int head[maxn]; bool vis[maxn]; int e; int pl[maxn],pr[ma…
Problem Description A thief is running away! We can consider the city to N–. The tricky thief starts his escaping if and only if there is a street between cross u and cross v. Notice that he may not stay at the same cross in two consecutive moment. T…
Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum…
题意:图上的点染色,给出的边的两个点不能都染成黑色,问最多可以染多少黑色. 很水的一题,用dfs回溯即可.先判断和当前点相连的点是否染成黑色,看这一点是否能染黑色,能染色就分染成黑色和白色两种情况递归,如果不能就单递归白色. 代码: #include <cstdio> #include <cstring> const int maxn = 110; int cas, v, e, M; bool g[maxn][maxn]; int color[maxn], rec[maxn]; v…
题目链接:https://vjudge.net/contest/219056#problem/A 推荐博客:https://blog.csdn.net/ck_boss/article/details/39429285 发现上面的这位大佬的思路和我一样,自己代码太多错误就参考了一下. 题意: 输入n,接下来会输入输入n个字符串,然后输入m,接下来会输入m对字符串,每一对表示左边的字符串可以变成右边的字符串,但是右边的不可以变成左边的.字符串不论大小写,现在要我们经过变换把一开始的n个字符里面的字符…
题目:http://codeforces.com/contest/85/problem/E 当然是二分.然后连一个图,染色判断是不是二分图即可.方案数就是2^(连通块个数). 别真的连边!不然时间空间都会爆. 别预处理 dis !要现算.不然会T. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define ll long long using namespace…
给一张无向图,要求你用黑白灰给点染色,且满足对于任意一个黑点,至少有一个白点和他相邻:对于任意一个白点,至少有一个黑点与他相邻,对于任意一个灰点,至少同时有一个黑点和白点和灰点与他相邻,问能否成功 Solution 显然灰色是多余的 首先考虑什么样的情况是不行的,显然仅在有孤立点的时候会挂,而连通图一定可以 所以我们只需要拿起每个连通块 DFS 随便染即可 #include <bits/stdc++.h> using namespace std; const int N = 1000005;…
http://poj.org/problem?id=3009 如果目前起点紧挨着终点,可以直接向终点滚(终点不算障碍) #include <cstdio> #include <cstring> using namespace std; ; int maz[maxn][maxn]; int n,m; ] = {,-,,}; ] = {,,,-}; bool in(int x,int y) { && x < n && y >= &&a…