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 hitfrank at 2010-06-15 10:19:12 on Problem 1781
#include <iostream>
using namespace std;
#include <vector>
int mypow(int a,int t)
{
	int res=1;
	for(int i=1;i<=t;i++)
		res*=a;
	return res;
}
int main()
{
	char ins[5];
	vector<int> v;
	while(scanf("%s",ins))
	{
		v.clear();
		if(ins[0]=='0' && ins[1]=='0' && ins[3]=='0')
			break;
		int num=((ins[0]-'0')*10+ins[1]-'0')*mypow(10,ins[3]-'0');
		int out=0;
		while(num>1)
		{
			if(num%2==0 && out==0)
			{
				v.push_back(0);
				num=num/2;
			}
			else if(num%2==1&&out==0)
			{
				num=num/2+1;
				v.push_back(0);
				out=1;
			}
			else if(num%2==0&&out==1)
			{
				v.push_back(1);
				num=num/2;
			}
			else
			{
				v.push_back(1);
				num=num/2;
				out=0;
			}
		}
		while(!v.empty())
		{
			int temp=v.back();
			v.pop_back();
			if(temp==0)
			{
				num=num+num-1;
			}
			else
			{
				num=num+num;
			}
		}
		cout << num << 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