poj 3543 iChess

iChess
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2225 Accepted: 979

Description

The Jury of NEERC’07 quarterfinals is proud to present you a new game — chess patience. This patience is played not with cards, but with black and white square tiles. The goal of the game is to place these tiles on a flat surface so that they form a square colored in a chess-like pattern. The square should be totally filled and be of the maximal possible size. There may remain some spare tiles, if they do not fit into the resulting square.

To make this game more popular, a computer version of this patience named iChess was developed. The rules are the same with the exception that the player is given the number of tiles, not the actual tiles. Also, the result of the patience is not the actual layout, but the side length (measured in tiles) of the maximal square with the required layout.

Your task is to write a program which can play iChess patience.

Input

The input file contains two integer numbers b and w — the number of black and white tiles respectively (0 ≤ b, w ≤ 10 000).

Output

The first line of the input file must contain a single integer number s — the side length of the maximum possible square made of at most b black and w white tiles.

If no square can be formed with the given tiles, output a single word “Impossible”.

Sample Input

#112 15
#20 0

Sample Output

#15
#2Impossible
#include<iostream>
#include<cmath>
using namespace std;
int mini(int a,int b)
{
if(a<b)
return a;
return b;
}

int main()
{
int b,w;
int res;
while(cin>>b>>w)
{
if(b==0 && w==0)
{
cout<<"Impossible"<<endl;
continue;
}
if(b==w)
res=sqrt((float)(b*2));
else
{
res=sqrt((float)(mini(b,w)*2+1));
}
cout<<res<<endl;
}
return 0;
}

 

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/23/2259846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值