1566. 4SUM
来源:互联网 发布:海岛奇兵坦升级数据 编辑:程序博客网 时间:2024/05/22 06:36
1566. 4SUM
Description
In this task, you are provided with four sets of integers. Your task consists of selecting one integer from each set, such that their sum is 0. You can assume that such selection exists.
Input
The first line of input contains four numbers, a, b, c, and d, separated by a space character, indicating the number of elements in each of the four sets. Each of these numbers is a positive integer 1 <= a, b, c, d <= 500. The following a + b + c + d lines contain the elements, each not smaller than −10000 and not larger than 10000. The elements of the first set are listed first, followed by the elements of the second set, etc.
Output
The output consists of the four integers, separated by a space character. The numbers must appear in the order in which they are listed in the input.
Sample Input
3 2 4 2517-8-13196-9100-147
Sample Output
17 -13 10 -14
暴力来,及时break就不会超时了。
#include <iostream>using namespace std;int main(){ int a,b,c,d,as[501],bs[501],cs[501],ds[501]; cin>>a>>b>>c>>d; for(int i=0;i<a;i++) cin>>as[i]; for(int i=0;i<b;i++) cin>>bs[i]; for(int i=0;i<c;i++) cin>>cs[i]; for(int i=0;i<d;i++) cin>>ds[i]; bool judge=false; for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { for(int k=0;k<c;k++) { for(int l=0;l<d;l++) { if(as[i]+bs[j]+cs[k]+ds[l]==0) { cout<<as[i]<<" "<<bs[j]<<" "<<cs[k]<<" "<<ds[l]<<endl; judge=true; break; } } if(judge==true) break; } if(judge==true) break; } if(judge==true) break; } return 0;}
- 1566. 4SUM
- 【Leetcode】4Sum (Sum)
- leetcode 2 sum 3sum 4sum
- 3Sum 3Sum Closest 4Sum
- 3Sum & 3Sum Closest & 4Sum
- 2Sum 3Sum 4Sum
- 3sum、3Sum closet、 4sum
- 3Sum, 3Sum Closest, 4 Sum
- Leetcode 2SUM-3SUM-4SUM
- Leetcode-2sum,3sum,4sum
- leetcode 2 sum & 3 sum & 4 sum
- 4Sum
- 4Sum
- 4Sum
- 4Sum
- 4Sum
- 4Sum
- 4Sum
- 希望大家不要把太多的责任和压力加在我身上
- 学习编程的方法
- Apache 负载均衡+Tomcat集群
- 【最短路+floyd】杭电 hdu 1217 Arbitrage
- 我们为何而生?
- 1566. 4SUM
- OpenGL 4.0 Shading Language Cookbook - 一本关于着色语言的新书
- C#的资源释源
- CentOS 6.2 64
- [转]从博士毕业的去向看要不要读博
- 一场关于Google成功和博士发表论文的大讨论
- 也谈谈12306网站面对大压力下的技术改进方案
- QR码生成原理
- sax详解(转)