Equal Sums (map的基本应用) 多学骚操作
2 seconds
256 megabytes
standard input
standard output
You are given kk sequences of integers. The length of the ii-th sequence equals to nini.
You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence ii (its length will be equal to ni−1ni−1) equals to the sum of the changed sequence jj (its length will be equal to nj−1nj−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 00) sequence is 00.
The first line contains an integer kk (2≤k≤2⋅1052≤k≤2⋅105) — the number of sequences.
Then kk pairs of lines follow, each pair containing a sequence.
The first line in the ii-th pair contains one integer nini (1≤ni<2⋅1051≤ni<2⋅105) — the length of the ii-th sequence. The second line of the ii-th pair contains a sequence of nini integers ai,1,ai,2,…,ai,niai,1,ai,2,…,ai,ni.
The elements of sequences are integer numbers from −104−104 to 104104.
The sum of lengths of all given sequences don't exceed 2⋅1052⋅105, i.e. n1+n2+⋯+nk≤2⋅105n1+n2+⋯+nk≤2⋅105.
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers ii, xx (1≤i≤k,1≤x≤ni1≤i≤k,1≤x≤ni), in the third line — two integers jj, yy (1≤j≤k,1≤y≤nj1≤j≤k,1≤y≤nj). It means that the sum of the elements of the ii-th sequence without the element with index xx equals to the sum of the elements of the jj-th sequence without the element with index yy.
Two chosen sequences must be distinct, i.e. i≠ji≠j. You can print them in any order.
If there are multiple possible answers, print any of them.
2
5
2 3 1 3 2
6
1 1 2 2 2 1
YES
2 6
1 2
3
1
5
5
1 1 1 1 1
2
2 3
NO
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
YES
2 2
4 1
In the first example there are two sequences [2,3,1,3,2][2,3,1,3,2] and [1,1,2,2,2,1][1,1,2,2,2,1]. You can remove the second element from the first sequence to get [2,1,3,2][2,1,3,2] and you can remove the sixth element from the second sequence to get [1,1,2,2,2][1,1,2,2,2]. The sums of the both resulting sequences equal to 88, i.e. the sums are equal.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + ;
struct node {
int x, y;
node(int x, int y): x(x), y(y) {}
node () {}
bool operator < (node const &a ) const {
return a.x < x;
}
};
map<int,node>mp;
int t, n, a[maxn];
int main() {
scanf("%d", &t);
int flag = ;
for (int k = ; k <= t ; k++) {
scanf("%d", &n);
int sum = ;
for (int i = ; i < n ; i++ ) {
scanf("%d", &a[i]);
sum += a[i];
}
if (flag) continue;
for (int i = ; i < n ; i++) {
int temp = sum - a[i];
if (mp.find(temp) != mp.end()) {
if (mp[temp].x != k) {
printf("YES\n");
printf("%d %d\n", k, i+);
printf("%d %d\n", mp[temp].x, mp[temp].y+);
flag = ;
}
}
if (flag) break;
mp[temp] = node(k, i);
}
}
if (!flag) printf("NO\n");
return ;
}
Equal Sums (map的基本应用) 多学骚操作的更多相关文章
- CF 988C Equal Sums 思维 第九题 map
		
Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
 - Codeforces Round #486 (Div. 3)-C. Equal Sums
		
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
 - 关于map  及 map 骚操作
		
关于map这个东西 很冷门.................. 但是,这个博客带你稍微了解一下map: map用法:一般当作一个下表无穷大的数组 关于它的骚操作:map的鬼畜用法,可以 ...
 - Guava中这些Map的骚操作,让我的代码量减少了50%
		
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. Guava是google公司开发的一款Java类库扩展工具包,内含了丰富的API,涵盖了集合.缓存.并发.I/O等多个方面.使用这些API一方面 ...
 - 闪电侠 Netty 小册里的骚操作
		
前言 即使这是一本小册,但基于"不提笔不读书"的理念,仍然有必要总结一下.此小册对于那些"硬杠 Netty 源码 却不曾在千万级生产环境上使用实操"的用户非常有 ...
 - 通过HTTP的HEADER完成各种骚操作
		
作为一名专业的切图工程师,我从来不care网页的header,最多关心Status Code是不是200.但是HEADER真的很重要啊,客户端从服务器端获取内容,首先就是通过HEADER进行各种沟通! ...
 - python20个骚操作
		
Python小白需要知道的 20 个骚操作! Python 是一个解释型语言,可读性与易用性让它越来越热门.正如 Python 之禅中所述: 优美胜于丑陋,明了胜于晦涩. 在你的日常编码中,以下技巧可 ...
 - Java 12 骚操作, String居然还能这样玩!
		
Java 13 都快要来了,12必须跟栈长学起! Java 13 即将发布,新特性必须抢先看! 栈长之前在Java技术栈微信公众号分享过<Java 11 已发布,String 还能这样玩!> ...
 - Python小白需要知道的 20 个骚操作!
		
Python小白需要知道的 20 个骚操作! Python 是一个解释型语言,可读性与易用性让它越来越热门.正如 Python 之禅中所述: 优美胜于丑陋,明了胜于晦涩. 在你的日常编码中,以下技巧可 ...
 
随机推荐
- py函数初识
			
一. 什么是函数 1. 我们到目前为止, 已经可以完成一些软件的基础功能了. 那么我们来完成这样一个功能: 约x print("拿出手机") print("打开陌&quo ...
 - Java学习笔记六:Java的流程控制语句之if语句
			
Java的流程控制语句之if语句 一:Java条件语句之if: 我们经常需要先做判断,然后才决定是否要做某件事情.例如,如果考试成绩大于 90 分,则奖励一朵小红花 .对于这种“需要先判断条件,条件满 ...
 - powerpoint教程资料,PPT的
			
Powerpoint,是微软公司设计的演示文稿软件,利用Powerpoint不仅可以创建演示文稿,还可以在互联网上召开面对面会议.远程会议或在网上给观众展示演示文稿,掌握利用PowerPoint是一项 ...
 - PAT-B java实现
			
注意:java提交PAT时,不需要加package : 类名必须是Main. 1001 害死人不偿命的(3n+1)猜想 (15) 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式 ...
 - 【转】手把手教你:Ubuntu14+apache2+django1.7+python2.7下网页/网站部署
			
本人亲自尝试了网上众多的部署网页/网站方法,绝大多数都未能试验成功,这次的项目光部署这块遇到了很多问题,大概耗费了我一个星期. 本着:王道论坛中的赠人玫瑰,手留余香的精神.我把自己一路所走的历程发布出 ...
 - 【Keras案例学习】 sklearn包装器使用示范(mnist_sklearn_wrapper)
			
import numpy as np from keras.datasets import mnist from keras.models import Sequential from keras.l ...
 - Putty的设置保存
			
用了好几年都不知道这功能, 以前每次在连接时只能手工更改字符为utf-8,当时在想怎么这么弱呢 后来才知道... 1 字符 Translation下 字体Appearance下 颜色Colours下 ...
 - VM打开虚拟机文件报错
			
用VM打开以前的虚拟机文件报错 Cannot open the disk 'F:/****.vmdk' or one of the snapshot disks it depends on. 这种问题 ...
 - fastlane自动化打包ipa并发布到firim或者蒲公英
			
1.打开终端,确保Xcode Command Line Tools 安装了最新版 xcode-select --install 2.安装fastlane sudo gem install -n /us ...
 - 【个人笔记】关于C++小数的处理
			
无论是C-Style还是C++-Style的输出,小数都会四舍五入.如果想要截断两种比较好的方法.第一种:利用sscanf输出成字符串,再人为地putchar().第二种:已知钦定保留6位小数,那么可 ...