HDU 4334 Trouble (数组合并)
Trouble
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5681 Accepted Submission(s):
1570
him a very difficult problem called 5-sum. Please help him.
The 5-sum problem
is defined as follows: Given 5 sets S_1,...,S_5 of n integer numbers each, is
there a_1 in S_1,...,a_5 in S_5 such that a_1+...+a_5=0?
(1≤N≤50). N test-cases follow. First line of each test-case contains a single
integer n (1<=n<=200). 5 lines follow each containing n integer numbers in
range [-10^15, 1 0^15]. I-th line denotes set S_i for 1<=i<=5.
there are a_1 in S_1,...,a_5 in S_5 such that a_1+...+a_5=0, otherwise output
"No".
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long a[],b[],c[],d[],e[],f[],g[];
long long i,j,x,k,l,n,t,flag=,p;
int main()
{
scanf("%lld",&t);
while(t--)
{
flag=;
//输入
scanf("%lld",&n);
for(i=;i<n;i++)
scanf("%lld",&d[i]);
for(i=;i<n;i++)
scanf("%lld",&e[i]);
for(i=;i<n;i++)
scanf("%lld",&f[i]);
for(i=;i<n;i++)
scanf("%lld",&g[i]);
for(i=;i<n;i++)
scanf("%lld",&c[i]);
//合并
int cnt1=;
for(i=;i<n;i++)
for(j=;j<n;j++)
a[cnt1++]=d[i]+e[j];
int cnt2=;
for(i=;i<n;i++)
for(j=;j<n;j++)
b[cnt2++]=f[i]+g[j]; //三四合并
sort(a,a+cnt1);
sort(b,b+cnt2);
//计算
for(i=;i<n;i++) //第五个数组 c[]
{
j=;
k=cnt2-;
while(j<cnt1 && k>=)
{
if(a[j]+b[k]+c[i]==0LL)
{
flag=;
break;
}
else if(a[j]+b[k]+c[i]<) //注意不要都写成i
j++;
else
k--;
} }
if(flag) cout<<"Yes"<<endl; //注意是Yes不是YES也不是yes
else cout<<"No"<<endl;
}
return ;
}
HDU 4334 Trouble (数组合并)的更多相关文章
- HDU 4334 Trouble (暴力)
Trouble Time Limit: 5000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- HDU 4334——Trouble——————【贪心&水题】
Trouble Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4334 Trouble
Trouble Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4334 Trouble(哈希|线性查找)
给定五个集合.问是否能从五个集合各取一个元素,使得元素之和为0. 这道题有两种做法,一种是哈希,然而之前没写过哈希.....比赛后从大神那copy了一份. 这里说还有一种. 对于这五个集合分为三组.1 ...
- Trouble HDU - 4334
Hassan is in trouble. His mathematics teacher has given him a very difficult problem called 5-sum. P ...
- go语言:多个[]byte数组合并成一个[]byte
场景:在开发中,要将多个[]byte数组合并成一个[]byte,初步实现思路如下: 1.获取多个[]byte长度 2.构造一个二维码数组 3.循环将[]byte拷贝到二维数组中 package gst ...
- 论php数组合并
注:尽量不要在循环中操作数据库. 1.两个一维数组合并成一个一维数组 $a = array('morning','afternoon','night'); $b = array('breakfast' ...
- PHP数组合并+与array_merge的区别分析 & 对多个数组合并去重技巧
PHP中两个数组合并可以使用+或者array_merge,但之间还是有区别的,而且这些区别如果了解不清楚项目中会要命的! 主要区别是两个或者多个数组中如果出现相同键名,键名分为字符串或者数字,需要注意 ...
- JS数组键值,数组合并,
eg: var arr = [] arr.test = '测试'; arr.push(1); arr.push(2); arr.obj = '对象'; console.log(arr);// [ 1, ...
随机推荐
- beego orm
http://beego.me/docs/mvc/model/overview.md go get github.com/astaxie/beego/orm Simple Usage package ...
- SGU 101 Domino 题解
鉴于SGU题目难度较大,AC后便给出算法并发布博文,代码则写得较满意后再补上.——icedream61 题目简述:暂略 AC人数:3609(2015年7月20日) 算法: 这题就是一笔画,最多只有7个 ...
- LaTeX工具——mathpix安利
官网: https://mathpix.com/ 效果看下图: 图片打不开点这里 识别效果还行,感觉很适合jbc/zcy这种不喜欢打LaTex公式的神仙.
- Android Studio 使用小结
从去年(2013年5月)Google发布Android Studio 0.1.0版本,到如今已经一年多了,已经升级到0.8.6 Beta版 ,从刚开始大家报怨bug多,编译困难,到如今已经基本趋于稳定 ...
- 基于阿里云服务器Linux系统部署JavaWeb项目
前段时间刚完成一个JavaWeb项目,想着怎么部署到服务器上,边学边做,花了点时间终于成功部署了,这里总结记录一下过程中所遇到的问题及解决方法.之所以选择阿里云,考虑到它是使用用户最多也是最广泛的云服 ...
- Selenium八大元素定位方式
1.根据id来定位: import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.sele ...
- 第三篇 Python执行方式和变量初始
第一个Python程序 可以打开notepad或者其他文本编辑器,输入:print("Hello Python!"),将文件保存到任意盘符下,后缀名是 .py 两种python程 ...
- ECharts 上传图片Example
前端 1.为ECharts准备一个div <div id="main" style="Height:400px"></div> 2.引入 ...
- GCD LCM 最大公约数 最小公倍数 分数模板 (防溢出优化完成)
自己写的一个分数模板,在运算操作时进行了防溢出的优化: ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } ll lcm(ll a, ll b) { ...
- HTML5的 input:file上传类型控制(转载)
http://www.haorooms.com/post/input_file_leixing HTML5的 input:file上传类型控制 2014年8月29日 66352次浏览 一.input: ...