CF40A题解

题目传送门
这道题不难,只要理解题意即可做出。

思路

我们定义 \(d\)\((x,y)\)\((0,0)\) 的距离。我们可以发现,当 \(d\) 是整数时, \((x,y)\) 在边界上。不在边界上怎么办呢?我们可以找出象限与颜色的关系。当 \((x , y)\) 在第一、三象限时,也就 \(x \times y>0\) 时,如果不在边界上,那么如果 \(d\) 为奇数( \(d\) 为 int 型),就输出为白,否则为黑。反之,当 \((x,y)\) 在第二、四象限时,也就是 \(x\times y<0\) 时,如果不在边界上,那么如果 \(d\) 为奇数,就输出为黑,否则为白。

代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int d=sqrt(x*x+y*y);//距离
    if(sqrt(x*x+y*y)==d)//是否在边界上
    {
        cout<<"black";
        return 0;
    }
    if(x*y>=0)          //第一、三象限
    {
        if(d%2==0) cout<<"black";
        else cout<<"white";
    }
    else                //第二、四象限
    {
        if(d%2!=0) cout<<"black";
        else cout<<"white";
    }
}

完美 AC !
这是本人的第二篇题解,望大家多多支持!

posted @ 2022-02-06 11:12  cycwss  阅读(31)  评论(0)    收藏  举报