POJ 2785 4 Values whose Sum is 0
Time Limit: 15000MS | Memory Limit: 228000K | |
Total Submissions: 13069 | Accepted: 3669 | |
Case Time Limit: 5000MS |
Description
Input
Output
Sample Input
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
Sample Output
5
Hint
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <iostream>
using namespace std; #define MAX_VAL 20000000 typedef struct
{
int nCount;
int x;
}Hash; Hash HashTable[MAX_VAL];
int a[], b[], c[], d[]; void InsertHT(int n)
{
int addr = n % MAX_VAL;
if (addr < )
{
addr += MAX_VAL;
}
while(HashTable[addr].nCount != && HashTable[addr].x != n)
{
addr = (addr + ) % MAX_VAL;
}
HashTable[addr].nCount++;
HashTable[addr].x = n;
} int SearchHT(int n)
{
int addr = n % MAX_VAL;
if (addr < )
{
addr += MAX_VAL;
}
while (HashTable[addr].nCount != && HashTable[addr].x != n)
{
addr = (addr + ) % MAX_VAL;
}
return HashTable[addr].nCount;
} int main()
{
int n, ans = ;
scanf("%d", &n);
memset(HashTable, , sizeof(HashTable));
for (int i = ; i < n; i++)
{
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
}
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
InsertHT(a[i] + b[j]);
}
}
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
ans += SearchHT(-c[i] - d[j]);
}
}
printf("%d\n", ans);
return ;
}
POJ 2785 4 Values whose Sum is 0的更多相关文章
- POJ 2785 4 Values whose Sum is 0(想法题)
传送门 4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 20334 A ...
- POJ - 2785 4 Values whose Sum is 0 二分
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 25615 Accep ...
- POJ 2785 4 Values whose Sum is 0(折半枚举+二分)
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 25675 Accep ...
- POJ 2785 4 Values whose Sum is 0(暴力枚举的优化策略)
题目链接: https://cn.vjudge.net/problem/POJ-2785 The SUM problem can be formulated as follows: given fou ...
- POJ 2785 4 Values whose Sum is 0(哈希表)
[题目链接] http://poj.org/problem?id=2785 [题目大意] 给出四个数组,从每个数组中选出一个数,使得四个数相加为0,求方案数 [题解] 将a+b存入哈希表,反查-c-d ...
- POJ 2785 4 Values whose Sum is 0 Hash!
http://poj.org/problem?id=2785 题目大意: 给你四个数组a,b,c,d求满足a+b+c+d=0的个数 其中a,b,c,d可能高达2^28 思路: 嗯,没错,和上次的 HD ...
- poj 2785 4 Values whose Sum is 0(折半枚举(双向搜索))
Description The SUM problem can be formulated . In the following, we assume that all lists have the ...
- [POJ] 2785 4 Values whose Sum is 0(双向搜索)
题目地址:http://poj.org/problem?id=2785 #include<cstdio> #include<iostream> #include<stri ...
- POJ 2785 4 Values whose Sum is 0 (二分)题解
思路: 如果用朴素的方法算O(n^4)超时,这里用折半二分.把数组分成两块,分别计算前后两个的和,然后枚举第一个再二分查找第二个中是否有满足和为0的数. 注意和有重复 #include<iost ...
随机推荐
- [游戏模版21] Win32 物理引擎 能量守恒
>_<:Only a little change in the function of MyPaint(...),besides the initial value have some c ...
- Spring - 初始化spring容器
2016.01.12 学习linux内核的过程中发现变相的提升了自己的工程能力.以前觉得spring这些东西很复杂麻烦.然而,学了linux内核再看这些东西,发现好简单. 学习spring首先就要学习 ...
- 深入理解 CSS 的 :before 和 :after 选择器(制作select下拉列表美化插件)
原文链接:http://www.cnblogs.com/LY-leo/p/5765598.html 对于 :before 和 :after 选择器,大家并不陌生,但是很少有人会主动去用它们.先解释下它 ...
- Leetcode 328 Odd Even Linked List 链表
Given 1->2->3->4->5->NULL, return 1->3->5->2->4->NULL. 就是将序号为单数的放在前面,而 ...
- asynchttpClient框架关于多文件批量上传的问题,改用xUtil
RequestParams params = new RequestParams(); params.add("ordernum",ordernum); params.add(&q ...
- Puppet Openstack Mitaka Design Summit小结
Puppet Openstack Design Summit小结 经过Puppet Openstack社区的不断努力,Puppet Openstack社区目前提供的Official Modules已经 ...
- quartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak解决
01-Jul-2016 07:24:20.218 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 80 ...
- Remove WebCakeDesktop
WebCakeDesktop.Updater.exe 是广告程序,卸载步骤参考 http://malwaretips.com/blogs/webcake-desktop-updater-exe-rem ...
- What is a Statistic?
from: https://controls.engin.umich.edu/wiki/index.php/Basic_statistics:_mean,_median,_average,_stand ...
- [LeetCode] Range Sum Query - Immutable & Range Sum Query 2D - Immutable
Range Sum Query - Immutable Given an integer array nums, find the sum of the elements between indice ...