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 |
怎样才能0MS~~只能做到基本不用内存,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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator