Data Recovery

Data Recovery

题面翻译

原来有 n n n 个数,给你其中的 m m m 个数 t 1 … m t_{1 \dots m} t1m,求这 n n n 个数是否可能最小值 为 m i n min min,最大值为 m a x max max

1 ≤ n , m , m i n , m a x , t i ≤ 100 1\le n,m,min,max,t_i\le 100 1n,m,min,max,ti100

题目描述

Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.

The testing goes in $ n $ steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only $ m $ .

The next day, the engineer’s assistant filed in a report with all the $ m $ temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn’t doubt his notes). So he asked you to help him. Given numbers $ n $ , $ m $ , $ min $ , $ max $ and the list of $ m $ temperatures determine whether you can upgrade the set of $ m $ temperatures to the set of $ n $ temperatures (that is add $ n-m $ temperatures), so that the minimum temperature was $ min $ and the maximum one was $ max $ .

输入格式

The first line contains four integers $ n,m,min,max $ $ (1<=m

Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.

输出格式

If the data is consistent, print ‘Correct’ (without the quotes). Otherwise, print ‘Incorrect’ (without the quotes).

样例 #1

样例输入 #1

2 1 1 2
1

样例输出 #1

Correct

样例 #2

样例输入 #2

3 1 1 3
2

样例输出 #2

Correct

样例 #3

样例输入 #3

2 1 1 3
2

样例输出 #3

Incorrect

提示

In the first test sample one of the possible initial configurations of temperatures is [1, 2].

In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].

In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.

模拟题来水题解

题目分析

所有情况分为两种

  1. 给出的m个数字均合法,即没有比min小的,没有比max大的
  • 如果合法,sort一下,判断数组第一个元素和最后一个元素是否分别等于min和max,若不相同,cnt++;
  • 判断cnt与 ( n - m ) 的关系,如果小于等于,则成立,反之不成立
  1. 给出的m个数字不合法,则直接输出Incorrect
#include
using namespace std;
const int N=105;
int a[N];
int n,m,in,ax,cnt;
int main()
{
	cin>>n>>m>>in>>ax;
	for(int i=0;i<m;i++){
		cin>>a[i];
		if(a[i]<in||a[i]>ax){
			cout<<"Incorrect"<<endl;
			return 0;
		}
	}
	sort(a,a+m);
	if(a[0]!=in)cnt++;
	if(a[m-1]!=ax)cnt++;
	if(cnt<=n-m)cout<<"Correct"<<endl;
	else cout<<"Incorrect"<<endl;
	return 0;
}

你可能感兴趣的:(暑假笔记,c++,算法,开发语言)