【SRM664-2】【BearPlaysDiv2】

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、动画、3D空间视频等,旨在为开发者提供全面的游戏开发知识和实践经验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

BearPlaysDiv2


Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain AB, and C stones, respectively. Limak's goal is to produce three equal piles.



Limak will try reaching his goal by performing a sequence of zero or more operations. In each operation he will start by choosing two unequal piles. Let's label their sizes X and Y in such a way that X < Y. He will then double the size of the smaller chosen pile by moving some stones between the two chosen piles. Formally, the new sizes of the two chosen piles will be X+X and Y-X.



You are given the ints AB, and C. Return "possible" (quotes for clarity) if there is a sequence of operations that will make all three piles equal. Otherwise, return "impossible".

Definition

 
Class:BearPlaysDiv2
Method:equalPiles
Parameters:int, int, int
Returns:string
Method signature:string equalPiles(int A, int B, int C)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):256
Stack limit (MB):256

Constraints

-AB and C will be between 1 and 500, inclusive.

Examples

0) 
 
10
15
35
Returns: "possible"
One valid sequence of operations looks as follows:
  • The initial pile sizes are 10, 15, and 35.
  • For the first operation Limak will choose the piles with 15 and 35 stones. After doubling the size of the smaller pile the new sizes of these two piles will be 30 and 20.
  • After the first operation the pile sizes are 10, 30, and 20.
  • For the second operation Limak will choose the piles with 10 and 30 stones. After doubling the size of the smaller pile the new sizes of these two piles will be 20 and 20.
  • After the second operation each pile has 20 stones, which means that Limak has reached his goal.
1) 
 
1
1
2
Returns: "impossible"
No matter what Limak does, there will always be two piles with a single stone each and one pile with 2 stones.
2) 
 
4
6
8
Returns: "impossible"
3) 
 
18
18
18
Returns: "possible"
Sometimes Limak can reach his goal without making any operations.
4) 
 
225
500
475
Returns: "possible"

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.



   bool can[1505][1505];
	void dfs(int a[3])
		{
			if(can[a[0]][a[1]]) return;
			can[a[0]][a[1]] = true;
			for(int i=0;i<3;i++)
			{
				for(int j=0;j<3;j++)
				{
					if(a[i] < a[j])
					{
						int t2[3] = {a[i]*2,a[j]-a[i],a[3-i-j]};
						dfs(t2);
					}
				}
			}
		}
	string equalPiles( int A, int B, int C ) {
		memset(can,0,sizeof(can));
		int s = A + B + C;
		int a[3] = {A,B,C};
		if(s % 3 == 0)
		{
			dfs(a);
			if(can[s/3][s/3]) return "possible";
		}
		return "impossible"; //
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值