Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:注意数据长度。。。。wa了一次

Posted by Golden_echo at 2019-07-30 17:37:56 on Problem 3262
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator