Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神拯救。。。无限WA。。QAQ

Posted by 201392347 at 2013-12-30 00:38:45 on Problem 3045 and last updated at 2013-12-30 00:40:37
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=60000+10;
struct cow_level{
int weight;
int strength;
int skill;
}cow[N];
int cmp(const void *a,const void *b)
{
    return ((int)(((cow_level *)a)->skill)-(int)(((cow_level *)b)->skill));
}
int main()
{
    int T;
    while(cin>>T){
    if(T==1)
    {
        cin>>cow[0].weight>>cow[0].strength;
        cout<<-cow[0].strength<<endl;
        continue;
    }
    int i;
    for(i=1;i<=T;i++)
    {
        cin>>cow[i].weight>>cow[i].strength;
        cow[i].skill=cow[i].weight+cow[i].strength;
    }
    qsort(&cow[1],T,sizeof(cow_level),cmp);
    int sum=0;
    i=1;
    sum+=cow[i].weight;
    int temp;
    int maxn=-(1<<29);;
    while(1)
    {
        i++;
        maxn=max(maxn,(int)sum-(int)cow[i].strength);
        if(i==T)
            break;
        sum+=cow[i].weight;
    }
    cout<<maxn<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator