ZOJ-3721 Final Exam Arrangement 贪心

  题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721

  容易的贪心题,排个序。。

 //STATUS:C++_AC_840MS_6272KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
//typedef __int64 LL;
//typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
int l,r;
int idx;
bool operator < (const Node &a)const {
return l!=a.l?l<a.l:r<a.r;
}
}p[N];
int cnt[N];
vector<int> q[N];
int n; int main()
{
// freopen("in.txt","r",stdin);
int i,j,tot,R;
while(~scanf("%d",&n))
{
tot=;
mem(cnt,);
for(i=;i<=n;i++)q[i].clear();
for(i=;i<n;i++){
scanf("%d%d",&p[i].l,&p[i].r);
p[i].idx=i+;
}
sort(p,p+n); R=-;
for(i=;i<n;i++){
if(p[i].l>=R){
tot++;
R=p[i].r;
}
R=Min(R,p[i].r);
q[tot].push_back(p[i].idx);
cnt[tot]++;
} printf("%d\n",tot);
for(i=;i<=tot;i++){
printf("%d",q[i][]);
for(j=;j<cnt[i];j++)
printf(" %d",q[i][j]);
putchar('\n');
}
putchar('\n');
}
return ;
}
上一篇:SAP标准教材列表


下一篇:【RabbitMQ】 WorkQueues