codeforces 1015A
1 second
256 megabytes
standard input
standard output
You are given a set of nn segments on the axis OxOx, each segment has integer endpoints between 11 and mm inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — coordinates of the left and of the right endpoints.
Consider all integer points between 11 and mm inclusive. Your task is to print all such points that don't belong to any segment. The point xxbelongs to the segment [l;r][l;r] if and only if l≤x≤rl≤x≤r.
The first line of the input contains two integers nn and mm (1≤n,m≤1001≤n,m≤100) — the number of segments and the upper bound for coordinates.
The next nn lines contain two integers each lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — the endpoints of the ii-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that li=rili=ri, i.e. a segment can degenerate to a point.
In the first line print one integer kk — the number of points that don't belong to any segment.
In the second line print exactly kk integers in any order — the points that don't belong to any segment. All points you print should be distinct.
If there are no such points at all, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.
3 5
2 2
1 2
5 5
2
3 4
1 7
1 7
0
In the first example the point 11 belongs to the second segment, the point 22 belongs to the first and the second segments and the point 55belongs to the third segment. The points 33 and 44 do not belong to any segment.
In the second example all the points from 11 to 77 belong to the first segment.
题意:给你一段1~n的区间,和m次覆盖,从l~r,求没有被覆盖的数
题解:emmm扫一遍覆盖就行,输出没有标记的数
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = +;
bool a[maxn];
int ans[maxn];
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
int l,r;
int n,m;
while(scanf("%d%d",&n,&m) !=EOF){
int k=;
memset(a,,sizeof(a));
while(n--){
cin>>l>>r;
for(int i=l;i<=r;i++){
a[i]=i;
}
}
for(int i=;i<=m;i++){
if(a[i]==){
ans[k++]=i;
}
}
if(k==){
puts("");
}else{
cout<<k<<endl;
for(int i=;i<k;i++){
cout<<ans[i]<<" ";
}
puts("");
}
}
return ;
}
codeforces 1015A的更多相关文章
- Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- narcissus
public class narcissus { public static void main(String args[]) { long u=0,t=0,h=0,y=0,k=0; for(long ...
- xampps 不能配置非安装目录虚拟主机解决方案
今天将前几天安装好的xampps配置下,准备开始php开发之旅,在我信心满满的将工作目录定在非安装目录上(安装目录在:D:\Program Files\xampps\apache\htdocs 我将 ...
- Django学习之天气调查实例(1):工程的开始
开始学习Django,一步一个脚印的进行.思考再三,还是以一个实例来开始学习.手里面正好有几万条单位天气传感器收集的数据,想做一个网页版的天气统计查询之类的小应用,也可以给学生体验,方便教学的进行(尽 ...
- Java中的IO流体系
Java为我们提供了多种多样的IO流,我们可以根据不同的功能及性能要求挑选合适的IO流,如图10-7所示,为Java中IO流类的体系. 注:这里只列出常用的类,详情可以参考JDK API文档.粗体标注 ...
- 使用uniflash串口烧写CC3200的常见问题
1. 在正常情况下,cc3200的烧写使用的是芯片的PIN55和PIN57,只要把SOP2上拉既可正常烧写,常见问题是烧写的时候没有上拉SOP2,正常运行SOP2留空,IAR只能仿真调试,不能下载程序 ...
- C#窗口抖动
用过QQ的窗口抖动功能吧.是不是觉得很神奇?很有意思?其实,仔细想想,使用的原理还是挺简单的:让窗口的位置不断快速地发生变化. 说出了原理,是不是一下恍然大悟?顿时理解了.我以前也想过如何实现这个功能 ...
- Windows Server Backup 裸机恢复
1.打开“Windows Server Backup”选择本地备份,并在操作栏选择“一次性备份”:(在实际生产环境中可以根据自己的需求,选择一次性备份还是选择备份计划.) 2.打开“一次性备份向导”, ...
- Mac上配置Cocos2d-x开发环境(多平台:Android/iOS)
下载以下资源: Cocos2d-x (http://www.cocos2d-x.org) Android NDK(http://developer.android.com/tools/sdk/ndk/ ...
- 虚拟现实-VR-UE4-创建一个自定义的角色 Character
我学习的资料使用的是老版本的ue4 新版本有好多都是不一样的,好多东西需要自己来摸索, 比如,在老板版本中,默认创建一个GameMode 是回自动创建构造函数发的,而新版本,是没有的,需要自己手动填写 ...
- VC++之运算符重载简单小结
封装继承和多态是面向对象三大基本支柱.在面向对象系统中有两种编译方式:静态联编和动态联编静态联编:也叫早期联编:指系统在编译时就决定如何实现某一动作,提供了执行速度快的优点.动态联编:也叫滞后联编:指 ...