POJ 2499 Binary Tree

思路:一步一步往上走即可

 

#include<iostream>
using namespace std;
int main()
{
	int sc;
	cin>>sc;
	for(int s=1;s<=sc;s++)
	{
		int a,b;
		cin>>a>>b;
		int left=0,right=0;
		while(1)
		{
			if(a>b)
			{
				int up=(a-1)/b;
				//int up=a/b;
				left+=up;
				a-=up*b;
			}
			else
			{
				int up=(b-1)/a;
				//int up=b/a;
				right+=up;
				b-=up*a;
			}
			if(a==1 &&b==1)
				break;
		}
		cout<<"Scenario #"<<s<<":"<<endl;
		cout<<left<<" "<<right<<endl<<endl;
	}
	return 0;
}


 

posted @ 2014-07-31 09:38  gongpixin  阅读(204)  评论(0编辑  收藏  举报