| ||||||||||
| 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了,求各路牛人指出错误(有说明)我的思路是将所有电缆长度存起来,然后一根一根加,存当前根数各个电缆的段数
如例子
802 0段 802
743 0段 743
457 0段 457
539 0段 539
当需一根时,取长度/(当前段数+1),取最大值(802),该电缆段数加1。
变成
802 1段 401
743 0段 743
457 0段 457
539 0段 539
需2根时,重复,取最大值(743),该电缆段数加1。
802 1段 401
743 1段 371
457 0段 457
539 0段 539
做k次,取最后增加段数的电缆求长度。
看了board的说法用了__int64,还是wa,请各位牛人看看是算法错还是程序错。
#include <iostream>
#include <math.h>
using namespace std;
int p[10005];//pieces
__int64 l[10005];//length
int main()
{
__int64 max;
int i,j,n,k,pos;
double temp;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
{
scanf("%lf",&temp);
l[i]=(__int64)(temp*100);
}
memset(p,0,sizeof(p));
for(i=1;i<=k;i++)
{
max=0;
pos=0;
for(j=0;j<n;j++)
if(l[j]/(1+p[j])>max)
{
pos=j;
max=l[j]/(1+p[j]);
}
p[pos]++;
}
i=l[pos]/p[pos];
temp=((double)i)/100;
printf("%.2lf\n",temp);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator