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

发个AC代码把,这题怎么没人做???

Posted by lx99410 at 2011-09-03 17:29:49 on Problem 1767
#include<stdio.h>
bool opt[35];int n,p,s,e,res;
int main(){
    scanf("%d", &n);
    while(n){opt[p++]=n&1;n>>=1;}
    for(s=0;s<p&&!opt[s];s++);
    for(e=s;e<p&&opt[e];e++);
    if(e==p){
      opt[0]=opt[1]=0;
      for(int i=2;i<p;i++)opt[i]=(i&1)^1;
    }
    else{
      int cnt=e-s-1;opt[e]=1;
      for(int i=s;i<e;i++)opt[i]=0;
      for(int i=2;i<p&&cnt;i++){opt[i]=(i&1)^1;if(!opt[i])cnt--;}
    }
    for(int i=p-1;i>=0;i--)res=(res<<1)|opt[i];
    printf("%d\n",res);
    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