3 条题解
-
1
蚌埠住了,凭什么我的Python过不去。
n = int(input()) students = [] ans = 0 for _ in range(n): lst = list(map(int, input().split( ))) students.append(lst) for i in range(n - 1): for j in range(i + 1, n): if (-5 <= students[i][0] - students[j][0] <= 5) and (-5 <= students[i][1] - students[j][1] <= 5) and (-5 <= students[i][2] - students[j][2] <= 5) and (sum(students[j]) - sum(students[i]) <= 10): ans += 1 print(ans)
但是C++的过了。麻。
#include<cstdio> #include<cmath> const int MAXN = 1010; struct Stu{ int chinese, math, english; }students[MAXN]; int main(){ int n, ans; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d %d %d", &students[i].chinese, &students[i].math, &students[i].english); } for(int i = 1; i <= n; i++){ for(int j = i + 1; j <= n; j++){ if((abs(students[i].chinese - students[j].chinese) <= 5) && (abs(students[i].math - students[j].math) <= 5) && (abs(students[i].english - students[j].english) <= 5) && (abs(students[i].chinese - students[j].chinese + students[i].math - students[j].math + students[i].english - students[j].english) <= 10)){ ans ++; } } } printf("%d", ans); return 0; }
信息
- ID
- 98
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 745
- 已通过
- 196
- 上传者