| ||||||||||
| 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 | |||||||||
要使用高精度吗?我用了4个64位来存储
还是WA。
以下是我的代码,请指教。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100006
#define M 100000000
typedef struct
{
__int64 d;
__int64 t;
}cow;
cow a[N];
bool cmp(cow a,cow b)
{
if(a.d==b.d) return a.t < b.t;
else return a.d > b.d;
}
int main()
{
int i,j,n;
__int64 sum[4],ti;
__int64 t,d;
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%I64d%I64d",&t,&d);
a[i].t=t;
a[i].d=d;
}
sort(a,a+n,cmp);
ti=0;
for(i=0;i<4;i++)
sum[i]=0;
for(i=0;i<n;i++)
{
sum[0]+=a[i].d*ti;
for(j=0;j<3;j++)
{
if(sum[j]>=M)
{
sum[j+1]+=sum[j]/M;
sum[j]=sum[j]%M;
}
}
ti+=2*a[i].t;
}
if(sum[3]!=0) printf("%I64d%08I64d%08I64d%08I64d\n",sum[3],sum[2],sum[1],sum[0]);
else if(sum[2]!=0) printf("%I64d%08I64d%08I64d\n",sum[2],sum[1],sum[0]);
else if(sum[1]!=0) printf("%I64d%08I64d\n",sum[1],sum[0]);
else printf("%I64d\n",sum[0]);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator