| ||||||||||
| 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 | |||||||||
再次感觉到Optimize的力量……#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator