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

怎样才能0MS~~

Posted by Hzj_jie at 2009-08-10 01:28:13 on Problem 3671
只能做到基本不用内存,16MS-32MS,怎样才能0MS~

#include <stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))

int main()
{
    int n;
    scanf("%d",&n);
    int c[2];
    c[0]=c[1]=0;
    int d[2];
    int i;
    int m=n<<1;
    scanf("%d",&d[0]);
    c[d[0]-1]=1;
    for(i=1;i<n;i++)
    {
        scanf("%d",&d[i&1]);
        if(d[(i+1)&1]==1 && d[i&1]==2)
        {
            int cur;
            cur=(c[1]<<1)+n-i;
            if(cur<m)
                m=cur;
        }
        c[d[i&1]-1]++;
    }
    if(c[0]==0 || c[1]==0)
        printf("0\n");
    else
    {
        m=min(min(c[0],c[1]),m-c[1]);
        printf("%d\n",m);
    }

    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