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

再次感觉到Optimize的力量……

Posted by Renegade at 2006-03-27 16:59:52 on Problem 2782
#include<iostream>
#include<algorithm>
using namespace std;
int i,j,n,l,item[100005],bc,sp;
bool opt;
bool cmp(const int a,const int b)
{
    return a>b;
}
int main()
{
    scanf("%d%d",&n,&l);
    for(i=0;i<n;i++)scanf("%d",item+i);
    sort(item,item+n,cmp);
    bc=n-1;
    sp=0;
    do{
        opt=false;
        for(i=sp;i<bc;i++){
            if(item[i]+item[bc]<=l){
                opt=true;
                bc--;
                sp=i+1; //有胆的去掉这一句试试看,呵呵
                break;
            }
        }
    }while(opt==true);
    printf("%d\n",bc+1);
}

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