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[4005], b[4005], c[4005], d[4005]; void InsertHT(int n) { int addr = n % MAX_VAL; if (addr < 0) { addr += MAX_VAL; } while(HashTable[addr].nCount != 0 && HashTable[addr].x != n) { addr = (addr + 1) % MAX_VAL; } HashTable[addr].nCount++; HashTable[addr].x = n; } int SearchHT(int n) { int addr = n % MAX_VAL; if (addr < 0) { addr += MAX_VAL; } while (HashTable[addr].nCount != 0 && HashTable[addr].x != n) { addr = (addr + 1) % MAX_VAL; } return HashTable[addr].nCount; } int main() { int n, ans = 0; scanf("%d", &n); memset(HashTable, 0, sizeof(HashTable)); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { InsertHT(a[i] + b[j]); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += SearchHT(-c[i] - d[j]); } } printf("%d\n", ans); return 0; }