| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:为什么总是wa,帮帮忙看下In Reply To:为什么总是wa,帮帮忙看下 Posted by:zhangyiviva at 2012-05-23 17:34:43 > //
> // main.cpp
> // poj2431
> //
> // Created by zhangyi zhang on 12-5-23.
> // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
> //
>
> #include <iostream>
> #include <queue>
> #include <algorithm>
>
> using namespace std;
>
> int a[10001];
> int b[10001];
>
> bool cmp(int a, int b)
> {
> return a>b;
> }
>
>
>
> int main(int argc, const char * argv[])
> {
> int n,l,p,dis;
> int ans = 0;
> int index = 0;
> priority_queue<int> queue;
>
> cin>>n;
> for(int i=0; i<n; i++)
> cin>>a[i]>>b[i];
> cin>>l>>p;
> sort(a,a+n,cmp);
> sort(b,b+n,cmp);
> dis = l;
> queue.push(p);
>
> while(index<n)
> {
> if(b[index]<=l)
> break;
> index++;
> }
>
> while(dis > 0)
> {
> for(; a[index]>=dis && index <n; index++)
> queue.push(b[index]);
> if(queue.empty())
> {
> cout<<-1<<endl;
> return 1;
> }
> dis -= queue.top();
> queue.pop();
> ans++;
> }
>
> cout<<ans-1<<endl;
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator