秋招模拟赛第34场(会员专属)|2023.07.08-科大讯飞提前批
- Status
- Done
- Rule
- IOI
- Problem
- 3
- Start at
- 2023-7-20 19:00
- End at
- 2023-7-20 20:30
- Duration
- 1.5 hour(s)
- Host
- Partic.
- 17
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
O(n)
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
int a, b, c;
cin >> a >> b >> c;
sort(s.begin(), s.end());
bool ok = false;
// 计算中位数,如果是奇数,则是最中间的,如果是偶数,则是中间两个的平均数
if (n % 2 == 1) {
if (s[n / 2] >= a) {
ok = true;
}
} else {
// (x + y) / 2 >= a ====> (x + y) >= 2 * a
if (s[n / 2 - 1] + s[n / 2] >= 2 * a) {
ok = true;
}
}
// 计算平均数,(s1+...+sn) >= b*n
if (accumulate(s.begin(), s.end(), 0) >= b * n) {
ok = true;
}
// 计算去掉最高和最低的平均数 (s1+...+sn-max-min) >= c * (n-2)
if (accumulate(s.begin(), s.end(), 0) - s[0] - s[n - 1] >= c * (n - 2)) {
ok = true;
}
puts(ok ? "Yes" : "No");
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
for (int i = 1; i <= T; ++i) {
solve();
}
return 0;
}
python代码
T = int(input()) # 输入测试数据的组数
for _ in range(T):
n = int(input()) # 期末考试科目数量
# 输入每门科目的平均成绩
scores = list(map(int, input().split()))
# 输入优秀班级需要满足的分数要求的判断值
a, b, c = map(int, input().split())
# 判断条件一:中位数不低于a
s = sorted(scores) # 求中位数
median = 0
if n % 2 == 0:
median = (s[n // 2] + s[n // 2 - 1]) // 2
else:
median = s[n // 2]
condition1 = median >= a
# 判断条件二:平均成绩整数部分不低于b
average_score = sum(scores) // n # 计算平均成绩
condition2 = average_score >= b
# 判断条件三:去除最高分和最低分后的剩余成绩平均数不低于c
remaining_scores = sum(scores) - max(scores) - min(scores) # 去除最高分和最低分后的剩余成绩之和
condition3 = remaining_scores // (n - 2) >= c
if condition1 or condition2 or condition3:
print("Yes")
else:
print("No")
Java代码
import java.util.*;
class Main {
static Scanner sc = new Scanner(System.in);
public static void solve() {
int n = sc.nextInt();
int[] s = new int[n];
for (int i = 0; i < n; ++i) {
s[i] = sc.nextInt();
}
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
Arrays.sort(s);
boolean ok = false;
// 计算中位数,如果是奇数,则是最中间的,如果是偶数,则是中间两个的平均数
if (n % 2 == 1) {
if (s[n / 2] >= a) {
ok = true;
}
} else {
// (x + y) / 2 >= a ====> (x + y) >= 2 * a
if (s[n / 2 - 1] + s[n / 2] >= 2 * a) {
ok = true;
}
}
// 计算平均数,(s1+...+sn) >= b*n
if (Arrays.stream(s).sum() >= b * n) {
ok = true;
}
// 计算去掉最高和最低的平均数 (s1+...+sn-max-min) >= c * (n-2)
if (Arrays.stream(s).sum() - s[0] - s[n - 1] >= c * (n - 2)) {
ok = true;
}
System.out.println(ok ? "Yes" : "No");
}
public static void main(String[] args) {
int T = sc.nextInt();
for (int i = 1; i <= T; ++i) {
solve();
}
}
}
小红是一家公司的老板,该公司共有n个部门。每个部门的平均考核成绩(取整后)分别记为s1,s2,...,sn,部门编号依次为1,2,...,n。
公司被称为优秀公司的条件是满足以下三个条件之一:
只要满足以上三个条件中的任意一个,小红的公司就可被评为优秀公司。
本题为多组测试数据,第一行输入一个正整数 T(1≤T≤1000),代表测试数据的组数.
对于每组测试数据,第一行输入一个正数 n(3≤n≤100)代表公司部门数量
第二行依次输入n个整数s1,s2,...sn(0≤si≤100),代表部门考核分数。
第三行依次输入三个整数a,b,c(0≤a,b,c≤100)依次代表优秀公司需要满足的分数要求的判断值。
对于每组测试数据,如果可以评为优秀公司,则一行输出一个字符串 “Yes”,否则输出“No”。(输出均不包含两边的双引号)
输入
3
3
66 66 66
99 70 60
4
99 10 60 25
43 49 43
6
46 64 0 100 60 88
62 88 77
输出
Yes
No
Yes