codeforces 430 A Points and Segments (easy)】的更多相关文章

题意:给出n个点,m个区间,需要给这些点涂上蓝色或者红色,使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 唉,题目的标题就标注了一个easy= = 最开始做的时候对点还有区间都排序了,模拟来做,可是错了 后来发现不管区间怎么样,只要红色和蓝色交替涂色, 就一定能满足“使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 ”这个条件 有点像上次做的cf交替输出奇数偶数那个A题 #include<iostream> #include<cstdio> #in…
A. Points and Segments (easy) Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/A Description Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on…
水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point{ int index, pos; Point(, ){ index = index_; pos = pos_; } bool operator < (const Point& a) const{ return pos < a.pos; } }; int ma…
题目 //终于看懂题目了,,,, //一条线段里面不是每个坐标上都有要染色的点,所以为了满足条件,只能考虑那些给出坐标的点 //所以就要排序一下了,不能直接根据坐标0 1 0 1…… #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; struct tt { int a,b; }aa[]; int cmp(tt x,tt y) { return x.a<y.…
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序输出颜色 思路:我会说我根本没想到怎么做吗?显然只要交替染色相差就不会大于1 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #inclu…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些不包含最大值的区间却能让差值变大. 所以没有问题. [代码] #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 300; int n,m; int a[N+10],segl[N+10],…
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了一番哈哈哈,其实这种精心服务一个班级的人还是很棒的一种感觉呢.思考思考最近的任务啊: (1)英语剧 (2)三下乡公益策划 (3)兼职 - 影视剧组后期特效 (3)三月底程序设计大赛天梯赛 (4)班会以及班级细节事件处理 (5)多模态视频处理 (6)兼职 - 校方艺考航拍记录 (7)六月四级考试和三下…
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a set of nn segments on the axis OxOx , each segment has integer endpoints between 11 and mm inclusive. S…
[CF429E]Points and Segments(欧拉回路) 题面 CF 洛谷 题解 欧拉回路有这样一个性质,如果把所有点在平面内排成一行,路径看成区间的覆盖,那么每个点被从左往右的覆盖次数等于从右往左的覆盖次数. 发现这题很类似上面这个东西. 将\(L\)向\(R+1\)连边,但是不能直接做欧拉回路,因为图不连通. 找到度数为奇数的所有点,把相邻的两个两两配对,然后在他们之间连条边,然后求解欧拉回路. 因为这样子配对完之后新增的区间不交,令黑色区间为\(+1\),白色区间为\(-1\),…
[CF429E]Points and Segments 题意:给你数轴上的n条线段$[l_i,r_i]$,你要给每条线段确定一个权值+1/-1,使得:对于数轴上的任一个点,所有包含它的线段的权值和只能是+1,-1或0. $n\le 10^5$ 题解:首先,我们用扫描线,整个数轴被分成若干个小区间.对于一个小区间,如果有偶数条线段包含它,则它的权值只能是0,否则可以是+1/-1.我们可以在所有权值为+1/-1的小区间处人为的增加一条线段,这样的话我们只需要让所有小区间权值都是0就行了. 嗯...每…
链接 CF429E Points and Segments 给定\(n\)条线段,然后给这些线段红蓝染色,求最后直线上上任意一个点被蓝色及红色线段覆盖次数之差的绝对值不大于\(1\),构造方案,\(n\leq10^5\) 欧拉回路. 考虑差分的思想(一般这样的区间覆盖问题都可以转化成差分,变成两两匹配问题.),一个线段被染色也就是\(l++\),\((r+1)--\) 设从\(l\)到\(r+1\)边为红色,\(r+1\)到\(l\)的边为蓝色. 那么我们就在考虑怎么样遍历这张图,使得每个点入度…
Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最后最大值与最小值的差值最大,并输出选择的区间 思路: 在n=300的时候,我们是枚举每个数作为最小值,应用所有覆盖它的区间,并且没 次都更行差值的最大值. 但是这里的n=1e5,所以我们不能用O(n*n*m),但是我们看到这里的m=300 所以可以从m入手,枚举区间,就是记录每个区间的两个端点,利用…
The only difference between easy and hard versions is a number of elements in the array. You are given an array aa consisting of nn integers. The value of the ii-th element of the array is aiai. You are also given a set of mm segments. The jj-th segm…
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据"每个点度都是偶数的图必然每个连通块都存在欧拉回路"这一条件构造出原图的欧拉回路进而求解答案.因此现在问题转化为如何构建出这样一张图出来. 首先一个非常直观的想法是对于每个区间新建一个左部点,对于数轴上每一个整点新建一个右部点,然后从每个区间表示的左部点向这段区间中所有整点表示的右部点连边,这样问题可…
Description 题面 题目大意:有 \(n\) 个区间 \([L_i,R_i]\) ,你要给每一个区间染红蓝,使得每一个位置被红色染过的次数与被蓝色染过的次数差的绝对值不大于\(1\) Solution 如果 \(L_i->R_i+1\) 连边 染色就变成了定向,那么一个点要被从左往右和从右往左经过的次数的绝对值之差不超过 \(1\) 发现一个环就是符合要求的,那么我们就可以试图找一个欧拉回路 考虑奇度点的处理: 我们把相邻的奇度点连起来就可以了 因为某些有交的区间并没有连边,我们用奇度…
题解: 方法非常巧妙的一道题 首先考虑要求全部为0怎么做 发现是个欧拉回路的问题(很巧妙) 直接dfs一遍就可以了 而这道题 要求是-1,1,0 我们可以先离散化 完了之后判断每个点被奇数还是偶数条边覆盖 如果是奇数,那么就多连一条边 另外有个细节是为了要用欧拉回路区间左开右闭 代码: #include <bits/stdc++.h> using namespace std; const int N=4e5; ; int n,cnt[N],rd[N],b[N],head[N],l1; stru…
Problem Introduction The goal in this problem is given a set of segments on a line and a set of points on a line, to count, for each point, the number of segments which contain it. Problem Description Task.In this problem you are given a set of point…
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line…
D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D Description Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (…
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments th…
A. In Search of an Easy Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as poss…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet a…
link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fixed point) #include <cstdio> using namespace std; ]; int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif i…
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points wi…
题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配达到最多. 作一次交换,最理想的情况是,在原来匹配好的序列中再匹配到两个数:最坏的情况是,即使作怎样的交换,都不可能再找到可以匹配的两个数,也就是说,根本不需要作交换.至于一般情况下,是可以再匹配到一个数的. 我是设了两个数组(分别有n个数):a(用来存储待判断的序列a)和b(依次存储0-n-1个数…
D. Vika and Segments time limit per test:  2 seconds     memory limit per test:  256 megabytes input : standard input output:  standard output Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensio…
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间看作整体,按照R从小到大排序.然后从最小的R开始枚举每个区间,要是枚举到这个区间L的时候,计算之前枚举的区间有多少个Li在L之后,那么这些Li大于L的区间的数量就是答案.那我每次枚举的时候用树状数组add(L , 1) 说明在L这个位置上出现了区间,之后枚举的时候计算L之前的和,然后i - 1 -…
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点值离散化,按照左端点从大到小排序,顺着这个顺序处理所有线段,那么满足在它内部的线段一定是之前已经扫到过的.用树状数组判断有多少是在右端点范围内. #include <iostream> #include <vector> #include <algorithm> #incl…
传送门 CodeForces 洛谷 Solution 考虑欧拉回路有一个性质. 如果把点抽出来搞成一条直线,路径看成区间覆盖,那么一个点从左往右被覆盖的次数等于从右往左被覆盖的次数. 发现这个性质和本问题十分的相似,那么我们就想一下怎么欧拉回路解决. 考虑显然可以差分对吧,如果把红色的贡献看成\(+1\),蓝色的看成\(-1\),那么就可以差分了. 那么这个也等价于欧拉回路,接着考虑对于奇数点,两两之间匹配就好了. 代码实现 代码戳这里…
E2 - Median on Segments (General Case Edition) 思路: 首先我们计算出solve(m):中位数大于等于m的方案数,那么最后答案就是solve(m) - solve(m+1) 那么怎么计算sovle(m)呢? 对于一个区间[l,r],如果它的中位数大于等于m,那么这个区间中 (大于等于m的数的个数) > (小于m的数的个数) 如果记a[i]大于等于m为+1,小于m 为 -1,即 sum(l, r)  > 0 我们枚举右端点 i ,并且同时计算sum(…