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

帮小弟看看这个算法是否可行,为什么总是WA呢

Posted by Gerhut at 2006-09-16 12:08:55 on Problem 1023
#include <iostream>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int k;
		cin>>k;
		char f[k+1];
		cin>>f;
		long long n;
		cin>>n;
		bool o[k];
		long long bign=0;
		for(int i=0;i<k;i++)
		{
			if(f[i]=='p')
			{
				bign+=(long long)(1<<(k-i-1));
				o[i]=true;
			}else
			        o[i]=false;
		}
		if(bign<n)
		{
			cout<<"Impossible";
			goto ending;
		}
		bign=bign-n;
		for(int i=0;i<k;i++)
		{
			if((long long)(bign&(long long)(1<<(k-i-1)))!=0)
				o[i]=!o[i];
			cout<<o[i];
		}
		ending:
                        cout<<endl;
		
	}
	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