coj1065: Scientific Conference
来源:互联网 发布:java项目评估技术方案 编辑:程序博客网 时间:2024/05/21 07:48
Description
Functioning of a scientific conference is usually divided into several simultaneous sections. For example, there may be a section on parallel computing, a section on visualization, a section on data compression, and so on.
Obviously, simultaneous work of several sections is necessary in order to reduce the time for scientific program of the conference and to have more time for the banquet, tea-drinking, and informal discussions. However, it is possible that interesting reports are given simultaneously at different sections.
A participant has written out the time-table of all the reports which are interesting for him. He asks you to determine the maximal number of reports he will be able to attend.
Input
The first line contains the number 1 ≤ N ≤ 100000 of interesting reports. Each of the next N lines contains two integers Ts and Te separated with a space (1 ≤ Ts < Te ≤ 30000). These numbers are the times a corresponding report starts and ends. Time is measured in minutes from the beginning of the conference.
Output
You should output the maximal number of reports which the participant can attend. The participant can attend no two reports simultaneously and any two reports he attends must be separated by at least one minute. For example, if a report ends at 15, the next report which can be attended must begin at 16 or later.
Sample Input
53 41 56 74 51 3
Sample Output
3
这道题比较郁闷,一开始用scanf总是超时,后来改成cin再关同步居然过了,一直都以为scanf比cin快,然后被狠狠打
脸,于是好好学习了cin和scanf的区别,这里推荐一篇大佬的博客
http://blog.sina.com.cn/s/blog_93294724010163rl.html
这道题主要是贪心,因为每个会议的结束时间都大于开始时间,所以以结束时间排序,然后for循环一个一个比对,如果
会议i的开始时间在会议i-1的结束时间之后,那么参加完会议i-1后可以继续参加会议i,此时将会议i的结束时间保存,答案
就出来了,挺水的贪心题
AC代码
#include<iostream>#include<algorithm>using namespace std;struct node{ int sta; int end;}con[100005];bool cmp(node a,node b){ if(a.end!=b.end) return a.end<b.end; else return a.sta<b.sta;}int main(){ ios::sync_with_stdio(false); int N; int cnt; int t; while(cin>>N) { cnt=1; for(int i=0;i<N;i++) { cin>>con[i].sta>>con[i].end; } sort(con,con+N,cmp); t=con[0].end; for(int i=1;i<N;i++) if(con[i].sta>t) { cnt++; t=con[i].end; } cout<<cnt<<endl; } return 0;}
- coj1065: Scientific Conference
- Scientific Conference
- Timus 1203. Scientific Conference
- Ural 1203. Scientific Conference
- ural 1203. Scientific Conference
- CSU Scientific Conference
- Ural 1203 Scientific Conference
- URAL 1203 Scientific Conference
- Ural 1203 Scientific Conference
- CSU1065-Scientific Conference-贪心
- URAL 1203 Scientific Conference (贪心)
- 1203. Scientific Conference 解题报告 URAL
- URAL 1203 Scientific Conference(贪心 || DP)
- URAL 1203Scientific Conference dp练习
- URAL 1203 Scientific Conference (贪心 + 优化)
- [贪心][DP][Ural 1203]Scientific Conference
- ural 1203. Scientific Conference(贪心or dp)
- CSU 1065 Scientific Conference 贪心(基本的调度问题)
- ABB软件的robotstudio怎么解决仿真问题(1)
- 阅读《重构 改善既有代码的设计》学习笔记
- 用GO生成指定长度的随机字符串
- 分享一个课自动整理代码的KEIL插件
- androidstudio Kotlin环境(离线)配置
- coj1065: Scientific Conference
- PHP解决IE浏览器下载文件名乱码问题
- CRC(循环冗余校验码)中的模2除运算
- 【个人笔记重点,不作为参考】主题: Ubuntu 14.04lts安装vncserver
- 【模板】Spaly区间翻转 (模板题:洛谷P3391文艺平衡树)
- JMeter录制Web脚本-简单示例(二)
- 50天走人计划
- 怎样防止羊毛党刷补贴?防护软件大火
- windows Nginx基本使用方法