3 条题解
-
2
啊啊啊啊啊......! 这道题究竟是什么意思!!! 难道不是说n大于28并且有至少有两个数相同就有人在同一月同一日生日吗?
哦,不对。
一年有12个月,题目中一月有28天(不过现实不是这样,
要是这是真的,一个月只要上28天课!还要减去周末!),根据某抽屉原理就共有12*28=336种可能?n要大于336?不对劲,n<=100呀!哦,又不对。
—————————————————— (错误解法和正确解法之间的分割线)
我们知道一年有12个月,那么想要有两位同学在同一日同一月生日,n一定要大于12(不等于12),并且数组a中一定有12个以上(不等于12)相同的数。 有13个人,就一定有两个人是同月,如果这13个人又恰好在同一天(对应数组a中一定有12以上,不等于12个相同的数),就一定有两个人是同月同日的。
不要忘了多组样例
AC代码如下:
#include <bits/stdc++.h> using namespace std; int cnt[30]; void solved(){ for (int i = 1; i <= 28; i++){ cnt[i] = 0; } int n, m; cin >> n; for (int i = 0; i < n; i++){ cin >> m; cnt[m] = cnt[m] + 1; } bool x = false; for (int i = 1; i <= 28; i++){ if (cnt[i] > 12){ x = true; } } if (x == true){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } int main(){ int t; cin >> t; while (t--) solved(); return 0; } -
0
#include<bits/stdc++.h> using namespace std; long long a[30]; int main(){ int t; cin >> t; for(int i = 1;i<=t;i++){ for(int j = 1;j<=28;j++){ a[j] = 0; } int n; cin >> n; for(int k = 1;k<=n;k++){ int x; cin >> x; a[x]++; } int c = 1; for(int nm = 1;nm<=28;nm++){ if(a[nm] >= 13){ c = 0; } } if(c == 1){ cout << "No" << endl; } else{ cout << "Yes" << endl; } } return 0; }
- 1
信息
- ID
- 6
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 651
- 已通过
- 65
- 上传者