Codeforces 27D(二分染色)】的更多相关文章

Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored using the same color as a neighbor region. He…
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs…
要点 将边作为染色,如果交叉则异色 #include <cstdio> #include <algorithm> #include <functional> using namespace std; int n, m; int a[101], b[101], c[101]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { scanf(&quo…
发现奇环不可行,偶环可行,考虑二分图.然后染色,方向全都从一种指向另一种就可以了,随意. ; int n, m, color[maxn]; vector<int> vc[maxn]; vector<P> e; void dfs(int cur, int co) { color[cur] = co; for (auto i : vc[cur]) { if (!color[i]) { dfs(i, - co); } else if (color[i] == color[cur]) {…
要点 会发现本质上棋盘分成了若干个独立集,本集合内的点放不放棋子并不影响其他集合内的 集合的划分方式就是满棋盘跳马步直到全跳过了,然后每个集合就分成两队,我们选人多的那队放棋子,人少那队当禁区 const int maxn = 1e3 + 5; const int nx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int ny[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int n, m; bool grid[maxn][maxn];…
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a.    然后求出这些学生能买自行车的最大数量,并且求当买下最大自行车数量时,总体花费私己钱的最少的钱. 我先来说以下二分搜索模板: //右值点不能取到的情况 int binary_search(vector<int>& nums,int left,int right, int targe…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. 思路: 转化为判定性问题.二分天数. 然后贪心,在规定天数以内,最后一天通过即可.需要保证每一科最后一天之前剩下还没考试的科目都来得及复习.(同时注意要要加上考试时间) 最后还要判定是不是所有的科目都通过了. */ #include<bits/stdc++.h> using namespace…
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{d[i][j-1], d[i+2^j-1][j-1]} RMQ的ST算法: void ST() //初始化 { memset(RMQ,,sizeof(RMQ)); ;i<=n;i++) RMQ[i][]=a[i]; ;(<<j)<=n;j++) ;i+(<<j)-<=…
    题意             n个数1~n按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外.     题解             这道题和POJ 3207差不多了..只是那道题只要判断是否存在不要输出方案...发现个很严重的问题..POJ 3207的数据实在是太弱了..我上一个程序里判断两个线段是否相交是个错了..都让我AC了..导致我做这题是沿用了思路...浪费了很多时间...          …