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:狂搜,30多MS,AC了,在hdu里面却WA了,怎么这样

Posted by yuanchuanshun at 2010-05-24 19:25:45 on Problem 3671
In Reply To:狂搜,30多MS,AC了,在hdu里面却WA了,怎么这样 Posted by:yuanchuanshun at 2010-05-24 19:25:33
> #include<stdio.h>
> int s1[30002],s2[30002],c[30002];
> int main()
> {
>     int i,j,N,min,temp;
>     while(scanf("%d",&N)!=EOF)
>     {
>        s1[0]=0; s2[0]=0;
>        for(i=1;i<=N;i++)
>        {
>           scanf("%d",&c[i]);
>           if(c[i]==1) { s1[i]=s1[i-1]+1; s2[i]=s2[i-1]; }
>           else { s2[i]=s2[i-1]+1; s1[i]=s1[i-1]; }
>        }
>        min=100000;
>        for(i=1;i<N;i++)
>        {
>            temp=s2[i]+s1[N]-s1[i];
>            if(temp<min)
>            min=temp;
>        }
>        if(min>s1[N]) min=s1[N];  //把很少部分的1改为2即可; 
>        if(min>s2[N]) min=s2[N];  //把很少部分的2改为1即可; 
>        printf("%d\n",min);
>     }
> }
> /*
> 7
> 2 1 1 1 2 2 1
> ==>2;
> 11
> 2 2 2 1 1 1 1 1 2 1 1
> ==>4; 
> */

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