4 Values whose Sum is 0(4 个总和为 0 的值)c语言

该博客讨论了一个名为SUM的问题,涉及找到四个列表A、B、C和D中元素的四元组(a, b, c, d),使得它们的和为零。输入包括四列表的相同大小n和其整数值,输出是满足条件的四元组数量。提供的C语言代码实现了二分查找算法来高效地计算结果,并给出了样例输入和输出。

题目描述
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 ) ∈ A x B x C x D are such that a + b + c + d = 0 . In the following, we assume that all lists have the same size n .

输入
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 .

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

题目描述
SUM问题可以表述如下:给定四个列表A,B,C,D的整数值,计算有多少个四重奏(a,b,c,d)∈A x B x C x D使得a + b + c + d = 0。在下文中,我们假设所有列表都具有相同的大小 n 。
输入
输入文件的第一行包含列表 n 的大小(此值可以最大为 4000)。然后,我们有n行包含四个整数值(绝对值大至228),分别属于A,B,C和D。
输出
对于每个输入文件,程序必须写入总和为零的四胞胎数。

样例输入
6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
样例输出
5
提示
示例说明:实际上,以下五个四胞胎的总和为零:(-45, -27, 42, 30), (26, 30, -10, -46), (-32, 22, 56, -46), (-32, 30, -75, 77), (-32, -54, 56, 30)。

在这里插入代码片
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <math.h>
int cmp ( const void *a , const void *b )
{
   
   
return *(int *)a -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值