• 思维,序列和


    Contest (nefu.edu.cn)

    Problem:G
    Time Limit:2000ms
    Memory Limit:65535K

    Description

    Catly有k个序列,每个序列有ni个元素,Catly想知道是否在k个序列中有两个序列,p和q,只要删除p中一个元素和q中一个元素,能使得q中元素和等于q中元素和

    Input

    第一行一个k(2<=k<=2e5) 代表有k个序列
    接下来有2*k行,一行为ni(1<=ni<=2e5)代表第i个序列有多少个元素,数据保证k<=n1+...+nk<=2e5
    下面一行有ni个数字aj(-10000<=aj<=10000)代表第i个序列中的元素

    Output

    如果有输出YES,并输出是哪两个序列x,y(x 
    

    Sample Input

    2
    5
    2 3 1 3 2
    6
    1 1 2 2 2 1

    Sample Output

    YES
    1 2
    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. #include
    13. #include
    14. #include
    15. using namespace std;
    16. typedef long long LL;
    17. const int N = 2e5 + 5;
    18. int n;
    19. int arr[N];
    20. unordered_map<int, pair<int, int>>mp;
    21. int main() {
    22. int k, sum = 0;
    23. scanf("%d", &k);
    24. for (int i = 1; i <= k; i++) {
    25. scanf("%d", &n);
    26. sum = 0;
    27. for (int j = 1; j <= n; j++) {
    28. scanf("%d", &arr[j]);
    29. sum += arr[j];
    30. }
    31. for (int j = 1; j <= n; j++) {
    32. if (!mp[sum - arr[j]].first)mp[sum - arr[j]].first = i;
    33. else if (!mp[sum - arr[j]].second && mp[sum - arr[j]].first != i)
    34. mp[sum - arr[j]].second = i;
    35. }
    36. }
    37. int x=k+1, y=k+1;
    38. for (unordered_map<int, pair<int, int>>::iterator i = mp.begin(); i != mp.end();i++) {
    39. //cout << "SSSSSSSSSS" << endl;
    40. if (i->second.second && i->second.first) {
    41. int a = i->second.first;
    42. int b = i->second.second;
    43. if (x + y > a + b || (x + y == a + b && b < y)) {
    44. x = min(a, b);
    45. y = max(a, b);
    46. }
    47. }
    48. }
    49. if (x != k + 1)
    50. printf("YES\n%d %d\n", x, y);
    51. else
    52. printf("NO\n");
    53. return 0;
    54. }

  • 相关阅读:
    Spring Cloud Gateway 使用 Redis 限流使用教程
    什么,api竟然有版本
    安装使用zookeeper
    【postgresql】
    猿创征文|云原生|kubernetes学习之RBAC(六)
    Leetcode1071. 字符串的最大公因子(三种方法,带详细解析)
    PHP 发送邮件
    gulp 错误集锦
    可微硬件:AI将如何重振摩尔定律的良性循环
    【Transform3D】转换详解(看完就会)
  • 原文地址:https://blog.csdn.net/Landing_on_Mars/article/details/133391413