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:请在ZOJ上过了的高手帮我看一下~为什么错

Posted by sakuragrass at 2005-08-16 16:57:23 on Problem 2573
In Reply To:请在ZOJ上过了的高手帮我看一下~为什么错 Posted by:sasnzy at 2005-08-15 17:38:42
没考虑n==1的情况,还有没有输出过河的过程。
> #include<iostream>
> #include<vector>
> #include<algorithm>
> using namespace std;
> int main()
> {
>   int n;
>   while (cin>>n)
>   {
>       if (!n) {cout<<0<<endl;continue;}
>       vector<int> t(n);                    //t记录每个人所需要的时间
>       for (int i=0;i<n;i++)
>           cin>>t[i];
>       if (n==1) {cout<<t[0]<<endl;continue;}
>       sort(t.begin(),t.end());             //将个人所需要的时间进行排序
>       int useTime=0;                       //令最快的人耗时a
>       int a=t[0];                          //次快的为b
>       int b=t[1];
>       while (n)
>       {
>           if (n==2) {useTime+=b;n=0;continue;}       //如果只剩2人(最快和次快的剩下)
>           if (n==3) {useTime+=a+b+t[2];n=0;continue;}      //如果只剩3人
>           if (n>=4)                                       //如果剩4人
>           {
>               int y=t[n-2];
>               if (2*b>=a+y) {useTime+=t[n-1]+a*2+y;n-=2;}     //方案1
>               else {useTime+=b*2+a+t[n-1];n-=2;}              //方案2
>           }
>       }
>       cout<<useTime<<endl;
>   }
> }
> 
> 我在ZOJ上不能AC~~但思路完全是按照书上的.....所有样例都正确....

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