[codeforces 1334A] Level Statistics 坑点较多

Codeforces Round #632 (Div. 2)   比赛人数14824

[codeforces 1334A]   Level Statistics   坑点较多

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址https://codeforces.com/contest/1334/problem/A

Problem Lang Verdict Time Memory
A - Level Statistics GNU C++17 Accepted 31 ms 0 KB

若能通过题中样例,并且如下数据能通过,那么坑点就基本避免了

Input:
2
2
0 1
1 1
2
1 0
1000 1003
Output:
NO
NO

比赛的第一题,读题就花了点气力,原以为该题就是在题意上难为参赛者,但是在编写代码过程中,发现该题坑点很多。

So when a player attempts the level, the number of plays increases by 1.

If he manages to finish the level successfully then the number of clears increases by 1 as well.

上面两句,是该题的核心。

两句大意是:尝试次数改变,不代表清理次数的改变。

在多次尝试中,可能有完成的情况,一旦有完成的情况,那么清理次数改变。

翻译成数学语言,就是合法的数据必须满足如下约束

p[i]>=p[i-1],c[i]>=c[i-1]
p[i]-p[i-1]>=c[i]-c[i-1]

AC代码如下

#include <stdio.h>
#define maxn 105
int p[maxn],c[maxn];
int main(){
	int t,n,i,flag;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(i=1;i<=n;i++)scanf("%d%d",&p[i],&c[i]);
		flag=0;
		for(i=1;i<=n;i++)
			if(p[i]>=p[i-1]&&c[i]>=c[i-1]&&p[i]-p[i-1]>=c[i]-c[i-1])continue;
			else flag=1;
		if(flag)printf("NO\n");
		else printf("YES\n");
	}
}
发布了660 篇原创文章 · 获赞 562 · 访问量 48万+

猜你喜欢

转载自blog.csdn.net/mrcrack/article/details/105446495