I: Scientific Conference
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
5
3 4
1 5
6 7
4 5
1 3
Sample Output
3
裸的贪心题
读入的时候就把每个结束时间记成读到数字+1然后排序,然后贪就好
顺便这里应该宣传一哈我自己写的贪心学习经历:(如果你看不到说明你(wo)不(hai)是(mei)聪(you)明(tian)的(diao)人(keng))
#include <bits/stdc++.h>
#define N 101000
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
struct con{
int b,e;
bool operator<(const con &a) const{
if(e!=a.e){
return e<a.e;
}else{
return b<a.b;
}
}
}c[N];
int main()
{
int n;
while(cin>>n){
for(int i=0;i<n;++i){
cin>>c[i].b>>c[i].e;
++c[i].e;
}
sort(c,c+n);
int res=1,en=c[0].e;
for(int i=1;i<n;++i){
if(c[i].b>=en){
++res;
en=c[i].e;
}
}
cout<<res<<endl;
}
return 0;
}
/**********************************************************************
Problem: 1065
User: CSUzick
Language: C++
Result: AC
Time:136 ms
Memory:2488 kb
**********************************************************************/