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

请问这个思路有问题么?

Posted by insotc at 2008-04-11 22:41:51 on Problem 1090
读入》除末尾零》运算
key[i]表示 状态全0 到 状态第i位为一之前全0的 步数 满足 key[1]=1 key[i]=key[i-1]*2+1
每次搜并且改变直到所有变为0
cnt表示当前序列有1的个数
void deal()
{
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=0)
        {
            a[i]=0;
            cnt--;
            res+=key[i];
            if(i==n)return ;
            if(i==n-1){res+=1;return;}
            if(cnt>2)//如果剩余序列还有两个以上1 下一位置0
            {
                if(a[i+1]==1)
                {
                    res+=1;
                    cnt--;
                    a[i+1]=0;
                }    
            }
            else if(cnt==2);//剩余序列还有两个1 不改变
            else //剩余序列只有一个1(末位) 下一位置1
            {
                res+=1;
                cnt++;
                a[i+1]=1;
            }    
            deal();   
            return ;
        }
    }
    return ;
}         

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