hdu1415-Jugs

http://acm.hdu.edu.cn/showproblem.php?pid=1415

第一种完全按照hdu要求输出,第二种属于特判;

思想参考灌水问题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>

using namespace std;

int main()
{
	int ca , cb , cc , x , y ;
	while( ~scanf( "%d%d%d" , &ca , &cb , &cc ) )
	{
		if( cb == cc )
			{
				printf( "fill B\n" ) ;
			}
		
		else if( ca == cc )
		{
			printf( "fill A\n" );
			printf( "pour A B\n" ) ;
		}
			else
			{
				x = y = 0 ;
				if( ca < cc )
				{
					while( 1 )
					{
						if( y == 0 )
						{
							y = cb ;
							printf( "fill B\n" ) ;
						}
					
						if( y > ca - x )
				   	    {y -= ca - x ;
			 				x = ca ;
							
							printf( "pour B A\n" ) ;
						}
						else
						{
							x += y ;
							y = 0 ;
							printf( "pour B A\n" ) ;
						}
						if( y == cc )
							break ;
						if( x == ca )
						{
							x = 0 ;
							printf( "empty A\n" );
						}
					}
				}
				else
				{
					while( 1 )
					{
						if( x == 0 )
						{
							x = ca ;
							printf( "fill A\n" ) ;
						}
						if( x > cb - y )
						{x -= cb - y ;
							y = cb ;
							
							printf( "pour A B\n" );
						}
						else
						{
							y += x ;
							x = 0 ;
							printf( "pour A B\n" ) ;
						}
						if( y == cc )
							break ;
						if( y == cb )
						{
							y = 0 ;
							printf( "empty B\n");
						}
					}
				}
			}
			printf( "success\n" ) ;
	}
	return 0 ;
}





#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>

using namespace std;

int main()
{
	int juga , jugb , n , t ;
	while( ~scanf( "%d%d%d" , &juga , &jugb , &n) )
	{
		if( jugb == n )
		{
			printf( "fill B\n" ) ;
			printf( "success\n" ) ;
			continue ;
		}
		if( juga == n )
		{
			printf( "fill A\n" ) ;
			printf( "pour A B\n" ) ;
			printf( "success\n" ) ;
			continue ;
		}
		t = 0 ; 
		while( t != n )
		{
			printf( "fill A\n" ) ;
			printf( "pour A B\n" ) ;
			t += juga ;
			if( jugb < t )
			{
				t -= jugb ;
				printf( "empty B\n" ) ;
				printf( "pour A B\n") ;
			}
		}
		printf( "success\n" );
	}
	return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值