[codeforces 1334A] Level Statistics has more pits

Codeforces Round # 632 (Div. 2)    14824

[codeforces 1334A] Level Statistics has more pits

See https://blog.csdn.net/mrcrack/article/details/103564004 for the general catalog

Online evaluation address https://codeforces.com/contest/1334/problem/A

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

If you can pass the sample in the question, and the following data can pass, then the pits are basically avoided

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

The first question of the game, it took a little effort to read the question. I thought that this question was difficult for the contestants in the meaning of the question, but in the process of writing the code, I found that this question has many pitfalls.

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.

The two sentences above are the core of the question.

The two sentences are: the change in the number of attempts does not mean the change in the number of cleanups.

In multiple attempts, there may be a completion situation, once there is a completion situation, then the number of cleaning changes.

Translated into a mathematical language, the legal data must meet the following constraints

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

AC code is as follows

#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");
	}
}

 

 

 

 

 

 

 

 

 

Published 660 original articles · praised 562 · 480,000 views

Guess you like

Origin blog.csdn.net/mrcrack/article/details/105446495