博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
K - 4 Values whose Sum is 0(中途相遇法)
阅读量:6948 次
发布时间:2019-06-27

本文共 2125 字,大约阅读时间需要 7 分钟。

K - 4 Values whose Sum is 0
Crawling in process... Crawling failed Time Limit:9000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit
Appoint description:System Crawler (2015-03-12)

Description

 

The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) $ \in$AxBxCxD are such that a + b + c + d = 0 . In the following, we assume that all lists have the same size n .

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The first line of the input file contains the size of the lists n (this value can be as large as 4000). We then have n lines containing four integer values (with absolute value as large as 228 ) that belong respectively to A, B, C and D .

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

For each input file, your program has to write the number quadruplets whose sum is zero.

Sample Input 

16-45 22 42 -16-41 -27 56 30-36 53 -37 77-36 30 -75 -4626 -38 -10 62-32 -54 -6 45

Sample Output 

5

Sample Explanation: Indeed, the sum of the five following quadruplets is zero: (-45, -27, 42, 30), (26, 30, -10, -46), (-32, 22, 56, -46),(-32, 30, -75, 77), (-32, -54, 56, 30).

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 #include
16 using namespace std;17 typedef long long LL;18 const int INF=0x5fffffff;19 const double EXP=1e-8;20 const int MS=4005;21 int A[MS],B[MS],C[MS],D[MS],n,sum[MS*MS];22 23 int main()24 {25 int T;26 scanf("%d",&T);27 while(T--)28 {29 scanf("%d",&n);30 for(int i=0;i

 

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/4335778.html

你可能感兴趣的文章
十大Intellij IDEA快捷键(转)
查看>>
Mysql - 解决Access denied for user ''@'localhost' to database 'mysql'问题
查看>>
JavaScript、CSS、JSP 实现用户注册页面与信息校验
查看>>
深入理解定位父级offsetParent及偏移大小
查看>>
使用PowerShell收集多台服务器的性能计数器
查看>>
jquery 中一些 特殊方法 的特殊使用 一览表
查看>>
yuv rgb 像素格式1
查看>>
通过PHP扩展phpredis操作redis
查看>>
如何在Swift里用UnsafeMutablePointer
查看>>
UML类图和时序图
查看>>
内存拷贝
查看>>
c_str()
查看>>
install ubuntu tweak on ubuntu lts 10.04,this software is created by zhouding
查看>>
Objective-C中一种消息处理方法performSelector: withObject:
查看>>
JSP实现分页显示
查看>>
关注HTML5安全
查看>>
ios中Pldatabase的用法(4)
查看>>
Leetcode: Search in Rotated Sorted Array
查看>>
windows上配置git
查看>>
新型智能芯片nxp----嗯质朴
查看>>