Codeforces Round #486 (Div. 3) C. Equal Sums

Codeforces Round #486 (Div. 3) C. Equal Sums

题目连接:

http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/C

Description

You are given k sequences of integers. The length of the i-th sequence equals to ni.

You have to choose exactly two sequences i and j (i≠j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to ni?1) equals to the sum of the changed sequence j (its length will be equal to nj?1).

Note that it‘s required to remove exactly one element in each of the two chosen sequences.

Assume that the sum of the empty (of the length equals 0) sequence is 0.

Sample Input

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

Sample Output

YES
2 6
1 2

题意

给定几个序列,问是否存在两个序列各删除一个元素后的和相等。

题解:

操作一个序列,将所有去掉一个元素之后的值保存下来,然后用 map 来检索是否存在答案。时间复杂度O(nlgn)

代码

#include <bits/stdc++.h>

using namespace std;

int T;
vector<int> v;
int n;
map<int, pair<int, int> > m;

int main() {
    cin >> T;
    for (int ii = 1; ii <= T; ii++) {
        cin >> n;
        v.clear();
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            v.push_back(x);
        }
        int sum = 0;
        for (auto i:v) sum += i;
        for (int i = 0; i < v.size(); i++) {
            if (!m.count(sum - v[i]) || m[sum - v[i]].first == ii) {
                m[sum - v[i]] = make_pair(ii, i+1);
            } else {
                cout << "YES" << endl;
                cout << ii << " " << i+1 << endl;
                cout << m[sum - v[i]].first << " " << m[sum - v[i]].second;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

原文地址:https://www.cnblogs.com/EDGsheryl/p/9153681.html

时间: 2024-10-08 23:48:29

Codeforces Round #486 (Div. 3) C. Equal Sums的相关文章

Codeforces Round #486 (Div. 3) B. Substrings Sort

Codeforces Round #486 (Div. 3) B. Substrings Sort 题目连接: http://codeforces.com/contest/988/problem/B Description You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for e

Codeforces Round #486 (Div. 3) A. Diverse Team

Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students

Codeforces Round #486 (Div. 3) D. Points and Powers of Two

Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/D Description There are n distinct points on a coordinate line, the coordinate of i-th point equals to xi. Choose a subset of

Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description Polycarp lives on a coordinate line at the point x=0. He goes to his friend that lives at the point x=a. Polycarp can

Codeforces Round #486 (Div. 3)

988A.http://codeforces.com/contest/988/problem/A 题意:给出n个数,让你从中取出m个不同的数组成一组 分析:模拟即可.当每个人为第一次出现时,标记这个位置可取.最后从可取的位置取m个即可 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 using namespace std; 6 const in

Codeforces Round #486 (Div. 3) E. Divisibility by 25

E. Divisibility by 25 能被25整除的充要条件就是末两位是00,25,50,75.如果没有过程中不出现前导0这一限制,显然对每种情况,贪心取尽量低位即可.本题的关键就在于如何满足这个条件,首先有个"显然"的方法:讨论...然后会发现情况太多,过于复杂.所以,我们只好从交换本身的性质入手,找找易于实现的写法.注意到我们最多移动3个数字的位置,最终两个最低位的数,可能还有一个非0数作为最高位,而根据交换的性质,可以发现先移动那个数对于最终的结果没有影响,按照题意我们要先

Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类

传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for一遍,记录四种可能对于的步数,再对四种可能讨论(有前导0的情况):自己是在数据中,该对了自己的代码, 看了队长和%王宣凯的代码,觉得那才是现场能ac的思路.--暴力交换: #include <iostream> #include <cstdio> #include <algori

【赛时总结】◇赛时&#183;V◇ Codeforces Round #486 Div3

◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了--为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Substrings Sort +传送门+   [暴力模拟] 题意 给出n个字符串,你需要将它们排序,使得对于每一个字符串,它前面的字符串都是它的子串(对于字符串i,则字符串 1~i-1 都是它的子串). 解析 由于n最大才100,所以 O(n3) 的算法都不会爆,很容易想到暴力模拟. 如果字符串i是字符串j的子串

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un