Gardener and the Array
题目描述:
The gardener Kazimir Kazimirovich has an array of
He wants to check if there are two different subsequences
A sequence
Two subsequences are considered different if the sets of indexes of their elements in the original sequence are different, that is, the values of the elements are not considered when comparing the subsequences.
输入描述:
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains one integer
The description of the array
The
It is guaranteed that the total sum of
输出描述:
For each set of input, print "Yes" if there exist two different subsequences for which
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
样例:
input:
5
3
2 1 5
2 2 4
2 2 3
2
2 1 2
1 2
4
3 1 2 4
2 2 4
4 1 2 5 6
2 2 5
5
3 3 1 2
3 2 5 3
5 7 2 3 1 4
5 1 2 6 3 5
3 2 6 3
2
1 1
1 2
output:
No
Yes
Yes
Yes
No
Note:
It can be proven that in the first test case there are no two different subsequences
In the second test case, one of the possible answers are following subsequences: the subsequence a formed by the element at position
In the third test case, one of the possible answers are following subsequences: the subsequence
AC代码:
#include <bits/stdc++.h> using namespace std; // 贪心的想,a和b或的数相同的越多他们就越接近 // 那么就让a或上所有的数,只要然后让b去掉一个数 // 只要去掉的那个数的每个位都曾经出现过一次,那么就代表b去掉这个数跟之前没区别 // 这样就可以找到f(a) = f(b); void solve() { int n; scanf("%d", &n); vector<vector<int>> a(n); map<int, int> b; for (int i = 0; i < n; i++) { int k; scanf("%d", &k); a[i].resize(k); for (int j = 0; j < k; j++) { scanf("%d", &a[i][j]); // 这一位的数出现的次数加1 b[a[i][j]]++; } } for (int i = 0; i < n; i++) { bool f = 1; for (int j = 0; j < a[i].size(); j++) { // 如果有一位数只出现过一次,就说明去掉这个数不行 if (b[a[i][j]] == 1) { f = 0; break; } } if (f) { printf("Yes\n"); return; } } printf("No\n"); } int main() { int T; scanf("%d", &T); while (T--) solve(); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】