【浮点取整】#39 A.Find Color

A. Find Color
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture:

The picture shows only the central part of the clock. This coloring naturally extends to infinity.

The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball.

All the points located on the border of one of the areas have to be considered painted black.

Input

The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000.

Output

Find the required color.

All the points between which and the origin of coordinates the distance is integral-value are painted black.

Sample test(s)
input
-2 1
output
white
input
2 1
output
black
input
4 3
output
black


这一题呢在Problemset里是40A,在Contest里是39A,我着实没辙了一下……这居然还有偏差的。。。

我既然都是#39这样来的,而且看到后面分Div1和Div2之后一个contest会有2个problemset的编号……就一直按照#Round的顺序写下去好了~


这个题本来想用直角坐标系转角坐标来写的。突然发现用不着……第一象限和第三象限是xy>0,第二象限和第四象限是xy<0

然后用sqrt(x*x+y*y)获得ρ得知距离远点距离,通过(int)强制转换获得【向0取整】的整型,从而可以判断奇偶

两者结合起来判断方位,别忘了在这之前特判一下落在分界上的情况~

Code:

#include <queue>
#include <cmath> 
#include <memory> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))

int main()
{
	double x,y;
	cin>>x>>y;
	double raw=sqrt(x*x+y*y);
	int p_sign=(x*y>0?1:0);
	int d_raw=(int)sqrt(x*x+y*y);
	int color=(d_raw%2)+p_sign;
	if(raw-(int)raw==0)cout<<"black"<<endl;
	else cout<<((color%2==0)?"white":"black")<<endl;
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值