AtCoder Beginner Contest 086 C - Traveling

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值