对于每组测试数据,输出一个整数,表示最早完成所有作业的时刻。
#include <stdio.h> #include <algorithm> using namespace std; struct action{ int s;///布置的时间 int f;///需要的时间 }a[1005]; bool cmp(const action &a,const action &b) { if(a.s<=b.s) return true; else return false; } int main() { int t; scanf("%d",&t); while(t--) { int time=0;///当前时间 int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].s,&a[i].f); sort(a,a+n,cmp); for(int i=0;i<n;i++) { if(time<=a[i].s) { time=a[i].s+a[i].f; } else time=time+a[i].f; } printf("%d\n",time); } return 0; }
原文:http://www.cnblogs.com/TreeDream/p/5277663.html