http://codeforces.com/contest/608/problem/A
题意:一个电梯,从s到0层,单项,给出n个人,每个人在某时间出现在某层,问要花多长时间把所有人运到0。初始电梯在s,每下一层话费时间1,上来人不花时间。
思路:由于电梯只能是单项,那么到达某一层的时候,一定要等到把这层中最晚来的那个接走。所以排序的时候按照楼层高到低为第一关键字,等待时间长到短为第二关键字。对于同一楼层出现的,只考虑第一个即可,也就是最后出现的。需要注意的是最后接完最后一个人以后把电梯运行道0层。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
/* *********************************************** Author :111qqz Created Time :2015年12月24日 星期四 00时32分24秒 File Name :code/cf/#336/A.cpp ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #define fst first #define sec second #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair using namespace std; const double eps = 1E-8; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; const int inf = 0x3f3f3f3f; const int N=105; int n; int s; struct node { int f,t; bool operator <(node b)const { if (f>b.f) return true; if (f==b.f&&t>b.t) return true; return false; } }q[N]; int main() { #ifndef ONLINE_JUDGE freopen("code/in.txt","r",stdin); #endif cin>>n>>s; for ( int i = 1 ; i<= n ;i++) cin>>q[i].f>>q[i].t; sort(q+1,q+n+1); int cur = s; int t = 0 ; q[0].f = -1; // for ( int i = 1 ; i <= n ; i++) cout<<q[i].f<<" "<<q[i].t<<endl; for ( int i = 1 ; i <= n ; i++) { if (q[i].f==q[i-1].f) continue; t+=cur-q[i].f; // cout<<"t:"<<t<<" "; cur = q[i].f; if (t<q[i].t) { t = q[i].t; } // cout<<"t2:"<<t<<endl; } t+=q[n].f; cout<<t<<endl; #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; } |
说点什么
您将是第一位评论人!