AtCoder 086 C
Problem Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0,0) at time 0, then for each i between 1 and N (inclusive), he will visit point (xi,yi) at time ti.
If AtCoDeer is at point (x,y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x−1,y), (x,y+1) and (x,y−1). Note that he cannot stay at his place. Determine whether he can carry out his plan.
题目大意:
给出n个数据,每个数据包含t,x,y(t按从小到大排序),要在每个时间t时依次走到点 ( x, y )
解题思路:
首先判断这个点和上个点的距离d (横坐标之差加纵坐标之差)是否小于等于 时间差t,其次(重点),判断距离d和时间差t的奇偶性是否想同,若相同则yes,反之no
代码:
#include<iostream>
#include<map>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstdio>
using namespace std;
typedef long long LL;;
const int MaxN = 1e5 + 5;
map <int, int> cnt;
struct point {
int x, y, t;
} mapp[MaxN];
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
int x, y, t;
scanf("%d%d%d", &t, &x, &y);
mapp[i].x = x, mapp[i].y = y, mapp[i].t = t;
}
mapp[0].x = 0, mapp[0].y = 0, mapp[0].t = 0;
for(int i = 1; i <= n; i++) {
int s, t;
s = fabs(mapp[i].x - mapp[i - 1].x) + fabs(mapp[i].y - mapp[i - 1].y);
t = fabs(mapp[i].t - mapp[i - 1].t);
if(s > t || s % 2 != t % 2 ) { //奇偶性的判断是关键
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}