标签:return lower and std 模拟 example seve check Matter
To make matters worse, one of the team member fell ill just before the deadline. So you, a brilliant student, are found by the team leader Dai to help the team check the problems‘ arrangement.
Now you are given the difficulty score of all problems. Dai introduces you the rules of the arrangement:
The team members have given you lots of possible arrangements. Please check whether these arrangements obey the rules or not.
There are multiple test cases. The first line of the input is an integer T (1 ≤ T ≤ 104), indicating the number of test cases. Then T test cases follow.
The first line of each test case contains one integer n (1 ≤ n ≤ 100), indicating the number of problems.
The next line contains n integers s1, s2, ... , sn (-1000 ≤ si ≤ 1000), indicating the difficulty score of each problem.
We kindly remind you that this problem contains large I/O file, so it‘s recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.
For each test case, output "Yes" (without the quotes) if the arrangement follows the rules, otherwise output "No" (without the quotes).
8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 999 1 1 2 3 4 5 6 7 8 9 11 999 1 3 5 7 9 11 13 17 19 21 10 15 1 13 17 1 7 9 5 3 11 13 1 1 1 1 1 1 1 1 1 1 1 1 2 10 2 3 4 5 6 7 8 9 10 11 10 15 1 13 3 6 5 4 7 1 14
No No Yes No Yes Yes No No
The first arrangement has 9 problems only, which violates the first rule.
Only one problem in the second and the fourth arrangement has a difficulty score of 1, which violates the third rule.
The easiest problem in the seventh arrangement is a problem with a difficulty score of 2, which violates the second rule.
After sorting the problems of the eighth arrangement by their difficulty scores in ascending order, we can get the sequence 1, 1, 3, 4, 5, 6, 7, 13, 14, 15. We can easily discover that |13 - 7| = 6 > 2. As the problem with a difficulty score of 13 is not the hardest problem (the hardest problem in this arrangement is the problem with a difficulty score of 15), it violates the fourth rule.
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <cstdio> #include <map> using namespace std ; #define maxn 200 int t , n ; int num[maxn] ; int main(){ scanf("%d" , &t) ; while(t--){ scanf("%d" , &n) ; for(int i=1 ; i<=n ; i++){ scanf("%d" , &num[i]) ; } int pos = 0 ; sort(num+1 , num+1+n) ; bool flag = true ; int sum = 0 ; if(n<10||n>13){ flag = false ; } for(int i=1 ; i<=n ; i++){ if(i!=1&&i!=n&&num[i] - num[i-1]>2){ flag = false ; } } // 注意不是有两个1而是最小的数字存在两个1 if(!(num[1] == 1 && num[2] == 1) ){ flag = false ; } if(flag == true ){ printf("Yes\n") ; }else printf("No\n") ; } return 0 ; }
标签:return lower and std 模拟 example seve check Matter
原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9065107.html