The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

POJ 3543-iChess 水题

看了之后才知道这个题很水哈,唯一要注意一下的是两种方块数量相差一的情况也是允许的;
假设方案可行后,得到的数再取floor就可以了;

#include <algorithm>
#include
<iostream>
#include
<cmath>
#include
<cstdio>
#include
<cstdlib>
using namespace std;


int main ()

{

    
double b,w;
    
while(scanf("%lf%lf",&b,&w)!=EOF)
    
{

        
if(b==0&&w==0)
        
{
            printf(
"Impossible\n");
            
continue;
        }

        
double temp;
        
if(b==w)
        
{
            temp
=floor(sqrt(2*b));
            printf(
"%.0f\n",temp);
            
continue;
        }

        
else if(b>w)
        
{

            temp
=floor(sqrt(w*2+1));
            printf(
"%.0f\n",temp);
            
continue;
        }

        
else if(b<w)
        
{

            temp
=floor(sqrt(b*2+1));
            printf(
"%.0f\n",temp);
            
continue;
        }



            

    }

    system(
"pause");
    
return 0;

}


 

posted on 2009-03-06 10:51 abilitytao 阅读(320) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理