题目链接 \(Description\) 给定平面上n个点,将这些点染成红or蓝色,要求每行.每列红色点与蓝色点数量的差的绝对值<=1.输出方案(保证有解). \(Solution\) 参考这 将每个横坐标.纵坐标分别看做一个点,将每个点(x,y)拆成x(row)->y(column)的边 这样我们可以将边染色,使得与每个点相连的两种颜色差<=1 于是对于所有的欧拉回路,我们可以直接交替染色 但是会有度数为奇数的点,这样的点一定有偶数个,我们对其两两配对连边,这样所有奇度数的点度数就都为…
Codeforces 题目传送门 & 洛谷题目传送门 首先考虑将题目中的条件转化为图论的语言.看到"行""列",我们很自然地想到二分图中行.列转点,点转边的套路,对于每一行 \(x\) 新建一个点 \(R(x)\),对于每一列 \(x\) 也新建一个点 \(C(y)\).考虑对于点 \((x_i,y_i)\),若其被染上红色,就连边 \(R(x_i)\to C(y_i)\),否则连边 \(C(y_i)\to R(x_i)\).那么显然对于每一行而言,其红色格…
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked n distinct points in the plane. i-th point is point (xi, yi). He wan…
Description 题面 题目大意:有一个的网格图,给出其中的 \(n\) 个点,要你给这些点染蓝色或红色,满足对于每一行每一列都有红蓝数量的绝对值之差不超过1 Solution 首先建立二分图,点\((x,y)\)视作 \(x->y'\) 的一条边 问题转化为:给边染色,使得每一个点的两种颜色的数量之差不超过\(1\) 如果原图存在欧拉回路,那么沿着欧拉回路交替染色即可(因为一定是偶环) 但是实际上存在度数为奇数的点,不能够成欧拉回路,所以我们先把它变成欧拉回路 容易发现度数为奇数的点的数…
题意: 二维平面上给出\(n\)个点,然后对每个点进行染色:红色和蓝色,要求位于同一行或同一列的点中,红色点和蓝色点的个数相差不超过1 分析: 正解是求欧拉路径,在这篇博客中看到一个巧妙的思路: 对于同一行中的点,进行两两分组,每组的两个点之间连一条边(可能会剩下孤立点). 同样地,同一列中的点,也进行两两分组,每组的两个点之间也连一条边. 将每条边的端点染上不同的颜色就满足了题目中的要求了. 为什么可以将得到的图进行二分染色呢? 这样的连接方式,保证了每个点左右两边最多有一边的点与其相连,上下…
Mike and Fish 我们可以把这个模型转换一下就变成有两类点,一类是X轴, 一类是Y轴, 每个点相当于对应的点之间建一条边, 如果这条边变红两点同时+1, 变蓝两点同时-1. 我们能发现这个图其实是个二分图, 我们可以随便取一个点开始走路, 红蓝间隔开来,那么中间的点就权值不变, 对于最末尾的点虽然权值有改变,但是只会改变一次, 就这样一直走路直到所有的边都遍历完. #include<bits/stdc++.h> #define LL long long #define fi firs…
传送门 分析 见正睿10.3笔记 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<queue> #…
D. Mike and Fish http://codeforces.com/contest/547/problem/D 题意: 给定平面上n个点,将这些点染成红或者蓝色,要求每行.每列红色点与蓝色点数量的差的绝对值<=1.输出方案(保证有解). 分析: 参考popoqqq的博客 将每行每列分别看做一个点,给定的每个点(x,y)拆成x->y的边,那么连边后的图是一个二分图. 这样我们可以将边染色,使得与每个点相连的两种颜色差<=1. 于是对于所有的欧拉回路,我们可以直接交替染色. 但是会…
「CF547D」 Mike and Fish 传送门 介绍三种做法. \(\texttt{Solution 1}\) 上下界网络流 我们将每一行.每一列看成一个点. 两种颜色的数量最多相差 \(1\),即红点的个数和蓝点个数范围都在 \([\lfloor \frac{cnt}{2}\rfloor,\lceil \frac{cnt}{2}\rceil]\) 当中. 若有一个点 \((x,y)\),则从第 \(x\) 行向第 \(y\) 列连边,容量为一.若有流量,则为红点,否则为蓝点. 最后从源点…
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int fac[N], cnt; void factor(int n) { cnt = ; int limit = sqrt(n); ; i <= limit; ++i) { ) fa…
codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i, a, b) for(int i=(a); i<(b); i++) #define per(i, a, b) for(int i=(b)…
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路,时间复杂度是O(mlogm) #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <vector> using namespace s…
正解貌似是大暴搜? 首先我们考虑这是一个二分图,建立网络流模型后很容易得出一个算法 S->行 容量为Num[X]/2; 行->列 容量为1 且要求(x,y)这个点存在 列->T 容量为Num[Y]/2 这样子跑网络流之后我们就得到了一组解 但是我们考虑输出方案 对于每一行,如果Num[X]为偶数,那么显然输出方案是正确的 但是如果Num[x]为奇数,多出的那个显然既有可能是红的也可能是蓝的 但关键是我们不能确定他是红的或者蓝的,因为他的状态也会影响对应的列 同样,列的考虑也是同理 所以我…
题意 题目链接 Sol 说实话这题我到现在都不知道咋A的. 考试的时候是对任意相邻点之间连边,然后一分没有 然后改成每两个之间连一条边就A了.. 按说是可以过掉任意坐标上的点都是偶数的数据啊.. #include<cstdio> #include<algorithm> #include<iostream> #include<vector> #include<cstring> #include<queue> #define Pair p…
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful…
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! As…
B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: standard input output: standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some si…
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is…
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m g…
题目: 题目原文链接:http://codeforces.com/contest/845/problem/C 题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间. 电视不能接连不间断的播放,例如TV1播放完1-2点的节目后不能接着播放2-3点的电视,除非在TV2上播放,如果TV2也正在播放则不能播放完清单. 思路: 1.对清单排序,让开始时间早的靠前,如果开始时间相同,结束时间早的靠前. 2.如果TV1已经结束.就把这一个节目的结束时间赋给TV1,然后看下一个节…
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, …
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Mihahim has a string s. He wants to delete exactly one character from it so that th…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
C. They Are Everywhere time limit per test: 2 seconds memory limit per test:256 megabytes input: standard input output: standard output Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from le…
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1,可以执行一次操作使ai,ai+1变为ai - ai + 1, ai + ai + 1.求出使得gcd(a1,a2,....an)>1所需要的最小操作数. 解题思路:首先,要知道如果能够实现gcd(a1,a2,....an)>1,那么a1~an肯定都是偶数(0也是偶数),所以我们的目的就是用最少的操…
题目链接:http://codeforces.com/problemset/problem/798/D 题目大意:从长度为n的序列A和序列B中分别选出k个下表相同的数要求,设这两个序列中k个数和分别为ta,tb,两个序列总和分别为asum,bsum.要求ta*2>asum&&tb*2>bsum,k<=n/2+1. 解题思路:首先,肯定要选n/2+1的吧.我们把序列A当成第一层,序列B当成第二层.第一层:按从大到小严格排好.在第二层上:每两个取大的那一个,那最后的和肯定&g…
C - Sorting Railway Cars   Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   CodeForces 606C Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are…
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据"每个点度都是偶数的图必然每个连通块都存在欧拉回路"这一条件构造出原图的欧拉回路进而求解答案.因此现在问题转化为如何构建出这样一张图出来. 首先一个非常直观的想法是对于每个区间新建一个左部点,对于数轴上每一个整点新建一个右部点,然后从每个区间表示的左部点向这段区间中所有整点表示的右部点连边,这样问题可…
题目链接:http://codeforces.com/problemset/problem/689/B 题目大意: 留坑 明天中秋~…
原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of choco…