哈希 poj 1480

计算可能的数目

a3*x3^3+a4*x4^3+a5*x5^5=-(a1*x1^3+a2*x2^3);

列举右边的  结果存到数组  z[i] 和为i的右边等式的数目

如果和小于0  +25000000

反正能存下就行了

然后列举一下左边的

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<string.h>
 4 #include<math.h>
 5 #include<vector>
 6
 7 using namespace std;
 8
 9 short z[25000010];
10 int a[5];
11
12 int main()
13 {
14     for(int i=0;i<5;i++)
15         scanf("%d",&a[i]);
16     for(int i=-50;i<=50;i++)
17     {
18         if(!i)
19         continue;
20
21         for(int j=-50;j<=50;j++)
22         {
23             if(!j)
24             continue;
25             int sum=-(a[0]*i*i*i+a[1]*j*j*j);
26             if(sum<0)
27             sum+=25000000;
28             z[sum]++;
29         }
30     }
31     int cnt=0;
32     for(int i=-50;i<=50;i++)
33     {
34         if(!i)
35         continue;
36
37         for(int j=-50;j<=50;j++)
38         {
39             if(!j)
40             continue;
41
42             for(int k=-50;k<=50;k++)
43             {
44                 if(!k)
45                 continue;
46                 int sum=a[2]*i*i*i+a[3]*j*j*j+a[4]*k*k*k;
47                 if(sum<0)
48                 sum+=25000000;
49                 cnt+=z[sum];
50             }
51         }
52     }
53     printf("%d\n",cnt);
54     return 0;
55 }
时间: 2024-08-05 03:40:11

哈希 poj 1480的相关文章

哈希—— POJ 3349 Snowflake Snow Snowflakes

相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33595   Accepted: 8811 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is

哈希 poj 3274

n个牛 二进制最多k位 给你n个数 求max(j-i)&&对应二进制位的和相同 7    1  1  1  倒的 6    0  1  1 7    1  1  1 2    0  1  0 1    1  0  0 4    0  0  1 2    0  1  0 3 4 5 6  加起来一样 前缀和 - 第一列 然后就发现对应相等就是和相同 根据 和  hash 和   有小于0的 下标注意一下 1 #include<stdio.h> 2 #include<algo

poj 3274 哈希

http://poj.org/problem?id=3274 Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For examp

poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30529   Accepted: 8033 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Y

poj 3349 数组的hash(最常用、最普通的哈希表建立)

http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search

POJ 3349-Snowflake Snow Snowflakes(哈希)

题目地址:POJ 3349 题意:给出n瓣雪花,每片雪花有六瓣,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:用哈希表存储,哈希表的关键码k用六瓣花瓣的长度的和取余(取余的数找一个大点的素数即可,这样可以减少内存的占用)一个数得到,表中为雪花的存储位置. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #inc

poj 3320 Jessica&#39;s Reading Problem (哈希高级应用)

Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spen

poj 2785 4 Values whose Sum is 0 哈希

题意: 给4个集合ABCD,问有多少种从中各取一个数和为0的方案. 分析: 枚举前两个数建哈希表,枚举后两个数查找即可. 代码: //poj 2785 //sep9 #include <iostream> using namespace std; const int maxN=4012; const int maxM=3999972; int a[maxN],b[maxN],c[maxN],d[maxN]; int hash[maxM+10]; int e; struct Edge { int

poj 1733 Parity game【哈希+并查集】

这道题题意我不想说了,但是有一个条件必须的说,就是1-2其实是0-2这条边,3-4是2-4这条边,但是困惑了好久,其他就是哈希给他一个地址 ,然后把注解看下方 #include <stdio.h> #include <string.h> #define maxx 10001 int par[maxx]; int rank[maxx]; void init() { for(int i=0;i<=maxx;i++) { rank[i]=0; par[i]=i; } } int f