跳到正文

题解

题解 AT3875 【Traveling】

chengni约 1 分钟
原文
文章信息与版本

文章信息

发布
2018年3月14日
收录
2026年10月14日
更新
2026年11月16日
篇幅
约 1 分钟
获赞
4

版本

  1. v1当前
代码
    模拟,利用一个简单的思想。先算出所在点与目标点的距离再和时间比对,先判断大小是否满足,在判断奇偶是否满足,如果都成立,更换初始位置和时间,继续判断下一个点
C++
#include<bits/stdc++.h>

using namespace std;

int main(){
	int n;
	cin>>n;
	int x=0,y=0;
	int t=0;
	int a,b,c;
	for(int i=1;i<=n;i++)
	{
		cin>>c>>a>>b;
		if(abs(x-a)+abs(y-b)>c-t)
		{
			cout<<"No";
			return 0;
		}
		if((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1)
		{
			cout<<"No";
			return 0;
		}
		if((abs(x-a)+abs(y-b))%2==1 &&(c-t)%2==0)
		{
			cout<<"No";
			return 0;
		}
		x=a;y=b;t=c;
	}
	cout<<"Yes";
	return 0;
}
原文