| ||||||||||
| 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 | |||||||||
把数按整数存了仍然WA,哪个高手能在给一组BT点的数据啊?#include<iostream.h>
#include<stdio.h>
#include<math.h>
const int Scope_Exceed=0;
const int Meet=1;
const int Larger=2;
const int Smaller=3;
int Constrain(long int length,long int *s);
double SearchLength(long int lscope,long int uscope,long int *s);
int N,K;
void main()
{
long int *Stock,sum=0,lscope=1,uscope,min=10000000;
double input;
scanf("%d %d",&N,&K);
Stock=new long int[N];
for(int i=0;i<N;i++)
{
cin>>input;
Stock[i]=(long int)(100*input);
if(Stock[i]<min)
min=Stock[i];
sum+=Stock[i];
}
uscope=min;
SearchLength(lscope,uscope,Stock);
printf("%.2f\n",SearchLength(lscope,uscope,Stock));
}
int Constrain(long int length,long int *s)
{
int sum=0;
for(int i=0;i<N;i++)
{
sum+=(int)(s[i]/length);
}
if(sum==K)
return Meet;
else if(sum<K)
return Larger;
else
return Smaller;
}
double SearchLength(long int lscope,long int uscope,long int *s)
{
int l,u,m;
double res=0;
l=lscope;
u=uscope;
while(l<=u)
{
m=(l+u)/2;
switch(Constrain(m,s))
{
case Meet:
res=m;
l=m+1;
break;
case Larger:
u=m-1;
break;
case Smaller:
res=m;
l=m+1;
break;
default:break;
}
}
return (double)res/100;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator