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 |
Re:注意数据长度。。。。wa了一次In Reply To:注意数据长度。。。。wa了一次 Posted by:lvweihua at 2017-08-10 16:40:12 > #include<cstdio> > #include<algorithm> > using namespace std; > const int MAXN=100005; > typedef long long ll; > struct Cow{ > int t,d; > }cow[MAXN]; > int cmp(const Cow &a,const Cow &b){ > return 1.0*a.d/a.t>1.0*b.d/b.t; //注意计算精度!!!!!!!!!!!!! > } > int main() > { > int N; > while(scanf("%d",&N)!=EOF){ > for(int i=0;i<N;i++){ > scanf("%d%d",&cow[i].t,&cow[i].d); > } > sort(cow,cow+N,cmp); > ll dmg=0,time=cow[0].t; //注意数据长度!!!!!!!!!!!!!! > for(int i=1;i<N;i++){ > dmg+=2*cow[i].d*time; > time+=cow[i].t; > } > printf("%lld\n",dmg); > } > return 0; > } 谢谢提醒 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator