大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席、团委团总支、社团社长都体验过一番了,现在差个班长也没试过,就来体验了一番哈哈哈,其实这种精心服务一个班级的人还是很棒的一种感觉呢。思考思考最近的任务啊:

  (1)英语剧

  (2)三下乡公益策划

  (3)兼职 - 影视剧组后期特效

  (3)三月底程序设计大赛天梯赛

  (4)班会以及班级细节事件处理

  (5)多模态视频处理

  (6)兼职 - 校方艺考航拍记录

  (7)六月四级考试和三下乡

  (8)七月暑假学车

  (9)兼职 - Eddy工作

  哇 大致想了想我真的可以忙死加学到死鸭,嘛,能者多劳,扛住就是胜利!!!好啦~不扯多,今天ACM集训队训练有道坑题得六个心眼,妈耶交了九次WA九次,最后一次交终于AC,哭迈

今日兴趣新闻:

MWC折叠屏刷屏背后的一场大戏:5家厂商恩怨情仇史

链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_9543883370009568888"%7D&n_type=0&p_from=1

  最近华为的新手机在朋友圈刷了不少圈,这种合并平板和手机的方式说不定真的会在未来畅销,因为这两者的用户需求量本来就是挺大的~,这篇新闻还是蛮有趣的讲了这几年的势头,可以看看。

------------------------------------------------题目----------------------------------------------------------

A. Points in Segments

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.

Input

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.

Output

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.

Examples

input


output

  

input

 

output

 

Note

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.

------------------------------------------------题目----------------------------------------------------------

(一) 原题大意:

    题目愿意是:输入四个量:L、V、left、right,其中从1到L为范围界,即1<=x<=L,当满足x可以整除V时,说明该处有灯笼,但left和right这个范围内没有灯笼,请统计有几个灯笼。

    题目感觉是不难的,但就是在一些端点特值处理上会有些问题。

(二) 题目分析:

    这里记录一下我原本的错误思想:

    第一次我的错误想法是直接就for暴力搜索了,结果就会超时Time limit exceeded on test 2

    错误代码:

#include<stdio.h>
int times,L,V,left,right;
int ans_light;
int main()
{
scanf("%d",&times);
while(times--)
{
ans_light = ;
scanf("%d %d %d %d",&L,&V,&left,&right);
for(int i = ;i<left;i++) if(i%V == ) ans_light++;
for(int i = right+;i<=L;i++) if(i%V == ) ans_light++;
printf("%d\n",ans_light);
}
return ;
}

    谨记千万没事就不要暴搜,看看有没有快捷的方式可以快速得到答案,这是ACM要训练我们的。

    第二个错误的想法:

    原本的想法是用了ceil函数,即向上取整,让V输入的数是个浮点数,代码大概如下:

             ans_light_1 = ceil((left - )/V);
ans_light_2 = ceil((L - right)/V);
printf("%d\n",ans_light_1+ans_light_2);

    然而这个做法,在V小于left的时候,答案是正确的,交了半天发现当V大于等于left的时候就会出现问题了

    所以第三个错误想法,我就把V和left的两种情况区分开来讨论了:

#include<stdio.h>
#include<math.h>
int times,L,left,right;
float V;
int ans_light_1,ans_light_2;
int main()
{
scanf("%d",&times);
while(times--)
{
ans_light_1 = ans_light_2 = ;
scanf("%d %f %d %d",&L,&V,&left,&right);
if(V<left)
{
ans_light_1 = ceil((left - )/V);
ans_light_2 = ceil((L - right)/V);
printf("%d\n",ans_light_1+ans_light_2);
}
else
{
ans_light_1 = L/int(V);
ans_light_2 = right/int(V) - left/int(V);
if(left % int(V) == )
{
printf("%d\n",ans_light_1 - ans_light_2 - );
continue;
}
printf("%d\n",ans_light_1 - ans_light_2);
}
}
return ;
}

    结果写到这里的时候,突然发现可以直接用一个公式直接求解:

    这里的灯笼数,实际上等于 L / V 减去 ( r / V - ( l - 1 ) / V ) 这样就能得到结果了。

(三) AC代码:

    因为代码比较简单,就不分块了,直接献上,给自己留个提醒。

#include<stdio.h>
#include<math.h>
int times,L,left,right;
int V;
int ans_light_1,ans_light_2;
int main()
{
scanf("%d",&times);
while(times--)
{
ans_light_1 = ans_light_2 = ;
scanf("%d %d %d %d",&L,&V,&left,&right);
ans_light_1 = L/V;
ans_light_2 = right/V - (left-)/V;
printf("%d\n",ans_light_1 - ans_light_2);
}
return ;
}

(四)AC截图:

注:我还是个渣渣辉,代码可能写得不够高效不够好,我也会努力优化,如果有更好的解法,真心希望您能够评论留言贴上您的代码呢~互相帮助互相鼓励才能成长鸭~~

『ACM C++』 Codeforces | 1066A - Points in Segments的更多相关文章

  1. 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3

    今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...

  2. 『ACM C++』 Codeforces | 1003C - Intense Heat

    今日兴趣新闻: NASA 研制最强推进器,加速度可达每秒 40 公里,飞火星全靠它 链接:https://mbd.baidu.com/newspage/data/landingsuper?contex ...

  3. 『ACM C++』 Codeforces | 1066B - Heaters

    今日不写日感,直接扔上今日兴趣点: 新研究称火星曾经有一个巨大的地下水系统 链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7 ...

  4. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011

    真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...

  5. 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)

    呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...

  6. 『ACM C++』HDU杭电OJ | 1416 - Gizilch (DFS - 深度优先搜索入门)

    从周三课开始总算轻松了点,下午能在宿舍研究点题目啥的打一打,还好,刚开学的课程还算跟得上,刚开学的这些课程也是复习以前学过的知识,下半学期也不敢太划水了,被各种人寄予厚望之后瑟瑟发抖,只能努力前行了~ ...

  7. 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)

    今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...

  8. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  9. 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester

    这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...

随机推荐

  1. 软件项目技术点(6)——结合鼠标操作绘制动态canvas画布

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 我们创建一个类封装了所有鼠标需要处理的事件. export class MouseEventInfo { el: HTMLElemen ...

  2. vue.js与angular.js的区别(个人)

    刚进入实训 讲师就要发一些什么比较高大上的东西,本人才疏学浅  浅浅的分享一下angularjs 和vue.js的区别.只是简单的理解一下 大神勿喷. 生实训之前学习的angular.js 只是理解了 ...

  3. PHP中empty、isset和is_null的使用区别

    关于PHP中empty().isset() 和 is_null() 这三个函数的区别,之前记得专门总结过,上次又被问到,网上已经很多,就用几个例子来说明: 测试用例选取: <?php $a;$b ...

  4. anroid之异步不如异步

    executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) 使用自定义的CorePoolSize为7的Executor(Executors.newFixedTh ...

  5. web images

    ps切图时,我们保存时会要求选择文件格式. 一般来说,如果图像的色彩丰富,没有透明度的要求,则选择为jpeg格式: 如果图像色彩不丰富,我们就选择为png-8的格式,注意:ps中要选择无杂边,无仿色 ...

  6. 从传输流收到意外的 EOF 或 0 个字节

    /// <summary> /// 发送POST请求 /// </summary> /// <param name="json"></pa ...

  7. Eclipse启动JVM机制

    1.Eclipse启动的时候,会启动一个JVM来运行eclipse(因为Eclipse是Java代码实现的) 2.Eclipse启动一个带main的主类的时候,会单独启动一个JVM来运行他. 3.Ec ...

  8. July 07th 2017 Week 27th Friday

    Learn wisdom by the follies of others. 要从别人的愚行中学到智慧. How to become smart or what characters should a ...

  9. Steeltoe

    谈谈Circuit Breaker在.NET Core中的简单应用 http://www.cnblogs.com/catcher1994/p/8975192.html 前言 由于微服务的盛行,不少公司 ...

  10. Spring 整合Hibernate 示例

    虽然Spring整合Hibernate早就会了,但经常在创建项目整合这两个框架的时候出一些低级错误.所以在这里写一个示例,以后再遇到错误时,再把遇到的错误或异常添加上. 一.创建一个动态WEB工程,添 ...