POJ 2785】的更多相关文章

题目链接:http://poj.org/problem?id=2785 题意:给定n行数字,每行4个数分别是a,b,c,d,现在要求能有多少个(a,b,c,d)组合并且和为0 思路:n^2统计所有(a+b),然后n^2统计(-1*(c+d)),再从(a+b)中找即可.注意map会超时.所以可以用Hash表或者排序+二分 #include<iostream> #include<algorithm> #include<cstring> #include<string&…
题目地址:http://poj.org/problem?id=2785 #include<cstdio> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> #include<stdbool.h> #include<time.h> #include<stdlib.h> #include<set> #in…
题目链接:http://poj.org/problem?id=2785 大意是输入一个n行四列的矩阵,每一列取一个数,就是四个数,求有多少种着四个数相加和为0的情况 首先脑海里想到的第一思维必然是一个个枚举,用四个for循环,那时间复杂度变成了On4,n的最大值是4000. 肯定会超时.那么,为了简化时间,首先我们可以开两个至少4000*4000的数组分别把第一列与第二列的和的情况 ,第三列与第四列的和的情况存起来.这样就只用考虑两个数组的情况. 然后把两个数组排序,一个数组从头部开始同时另一个…
[题目链接] http://poj.org/problem?id=2785 [题目大意] 给出四个数组,从每个数组中选出一个数,使得四个数相加为0,求方案数 [题解] 将a+b存入哈希表,反查-c-d [代码] #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N=4500,mod=1<<22; int n,a[N],b[N],c[…
http://poj.org/problem?id=2785 题目大意: 给你四个数组a,b,c,d求满足a+b+c+d=0的个数 其中a,b,c,d可能高达2^28 思路: 嗯,没错,和上次的 HDU 1496 Equations hash(见http://blog.csdn.net/murmured/article/details/17596655)差不多,但是那题数据量小,hash值很好得到,不用取模运算. 而这题数据量很大.那就采用开散列的思想. hash值怎么选取? 上次我看的书中是建…
传送门:Problem 2785 题意: 给定 n 行数,每行都有 4 个数A,B,C,D. 要从每列中各抽取出一个数,问使四个数的和为0的所有方案数. 相同数字不同位置当作不同数字对待. 题解: 如果采用暴力的话,从4个数列中选择数组合,共有(N^4)种选择,故时间复杂度为O(N^4),指定会超时. 但,如果将它们分成 AB,CD两组,每组只有 N^2 个组合,而 N 的数据范围为 N < 4000,故采用此种方法不会超时. AC代码: #include<iostream> #incl…
传送门 4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 20334   Accepted: 6100 Case Time Limit: 5000MS Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute…
找四个数的和为0 题目大意:给定四个集合,要你每个集合选4个数字,组成和为0 这题是3977的简单版,只要和是0就可以了 #include <iostream> #include <algorithm> #include <functional> #define MAX 4001 using namespace std; typedef long long LL_INT; ][MAX], set_sum1[MAX*MAX]; LL_INT *Binary_Lower_B…
4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 13069   Accepted: 3669 Case Time Limit: 5000MS Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how…
4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 14475   Accepted: 4138 Case Time Limit: 5000MS Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how…