题目链接:http://acm.swust.edu.cn/problem/0166/

Time limit(ms): 5000      Memory limit(kb): 65535
 

有如下方程组: A1*x1^3+A2*x2^3+A3*x3^3+A4*x4^3+A5*x5^3=0,其中A1…A5都在[-50,50]内。 如果(x1,x2,x3,x4,x5)(其中-50<=xi<=50,xi!=0)能让该等式成立,就说(x1,x2,x3,x4,x5)为其一组解,现在的问题是要问你该等式共有多少组解。

Description

输入包括5个系数 A1,A2,A3,A4,A5

注意:这里是多组输入哈,太坑爹了!

Input

输出该方程解的数目

Output
1
23 45 36 13 57
Sample Input
1
1436
 
 
解题思路:明显的hash,但是想了想,这里的系数[-50,50],x范围[-50,50],
     那么求得的解的变换范围为[-12500000,12500000]数组大小25000000(内存直接爆了)
     表示智商捉急~~然后晓得了还有short 这个东东(http://bbs.csdn.net/topics/370037447
     然后卡到内存ac了
代码如下:
 #include <stdio.h>
#include <string.h>
#define maxn 25000010
short hash[maxn];
int main(){
int a[], x1, x2, x3, x4, x5, cnt, temp;
while (scanf("%d%d%d%d%d", &a[], &a[], &a[], &a[], &a[]) != EOF){
cnt = ;
memset(hash, , sizeof(hash));
for (x1 = -; x1 <= ; x1++){
if (x1){
for (x2 = -; x2 <= ; x2++){
if (x2){
temp = a[] * x1*x1*x1 + a[] * x2*x2*x2;
if (temp<)
temp += maxn;
hash[temp]++;
}
}
}
}
for (x3 = -; x3 <= ; x3++){
if (x3){
for (x4 = -; x4 <= ; x4++){
if (x4){
for (x5 = -; x5 <= ; x5++){
if (x5){
temp = -(a[] * x3*x3*x3 + a[] * x4*x4*x4 + a[] * x5*x5*x5);
if (temp<)
temp += maxn;
if (hash[temp])
cnt += hash[temp];
}
}
}
}
}
}
printf("%d\n", cnt);
}
return ;
}

但是发现有人低内存ac了,然后,然后,把每次求得的值MOD一个数,然后~~~(智商啊)

 #include <stdio.h>
#include <math.h>
#include <string.h>
#define maxn 200005
int hash[maxn][], num[maxn];
int main(){
int i, j, k, l, cnt, tmp, mark, a[];
while (~scanf("%d%d%d%d%d", &a[], &a[], &a[], &a[], &a[])){
memset(num, , sizeof(num));
cnt = ;
for (i = -; i <= ; i++){
if (i){
for (j = -; j <= ; j++){
if (j){
tmp = a[] * i*i*i + a[] * j*j*j;
mark = abs(tmp) % maxn;
hash[mark][num[mark]] = tmp;
num[mark]++;
}
}
}
}
for (i = -; i <= ; i++){
if (i){
for (j = -; j <= ; j++){
if (j){
for (k = -; k <= ; k++){
if (k){
tmp = a[] * i*i*i + a[] * j*j*j + a[] * k*k*k;
mark = abs(tmp) % maxn;
for (l = ; l < num[mark]; l++)
if (tmp == hash[mark][l]) cnt++;
}
}
}
}
}
}
printf("%d\n", cnt);
}
return ;
}

[Swust OJ 166]--方程的解数(hash法)的更多相关文章

  1. POJ 1186 方程的解数

    方程的解数 Time Limit: 15000MS   Memory Limit: 128000K Total Submissions: 6188   Accepted: 2127 Case Time ...

  2. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  3. NOI2001 方程的解数

    1735 方程的解数 http://codevs.cn/problem/1735/ 2001年NOI全国竞赛  时间限制: 5 s  空间限制: 64000 KB     题目描述 Descripti ...

  4. cogs 304. [NOI2001] 方程的解数(meet in the middle)

    304. [NOI2001] 方程的解数 ★★☆   输入文件:equation1.in   输出文件:equation1.out   简单对比时间限制:3 s   内存限制:64 MB 问题描述 已 ...

  5. P5691 [NOI2001]方程的解数

    题意描述 方程的解数 求方程 \(\sum_{i=1}^{n}k_ix_i^{p_i}=0(x_i\in [1,m])\) 的解的个数. 算法分析 远古 NOI 的题目就是水 类似于这道题. 做过这道 ...

  6. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  7. 计蒜客 方程的解数 dfs

    题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...

  8. [ NOI 2001 ] 方程的解数

    \(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...

  9. NTC热敏电阻温度计算方法,Steinhart-Hart方程和B值法(转)

    NTC热敏电阻计算器使用方法 NTC热敏电阻计算器 V1.0 10K负温度系数热敏电阻(NTC)温度与阻值对应关系表 Rt = R(25℃)*EXP[B*(1/T - 1/(T+25))] 说明: 1 ...

随机推荐

  1. servlet三种实现方式之二继承GenericServlet开发

    servlet有三种实现方式: 1.实现servlet接口 2.继承GenericServlet 3.通过继承HttpServlet开发servlet 第二种示例代码如下(已去掉包名): //这是第二 ...

  2. jquery的extend()函数

    extend()是在写插件的过程中常用的方法,该方法有一些重载原型. 1.该方法的原型是: extend(dest,src1,src2,src3...); 它的含义是将src1,src2,src3.. ...

  3. Android 开发笔记“关闭默认键盘”

    1.打开AndroidManifest.xml文件 2.在对应的activity中增加配置信息 android:windowSoftInputMode="stateHidden"

  4. Ubuntu 12.04中文输入法的安装(转)

    Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu的中文系统中自带了中文输入法,通过Ctrl+S ...

  5. ISO/IEC14443和15693的对比有何具体区别

    ISO14443 ISO14443A/B:超短距离智慧卡标准.这标准订出读取距离7-15厘米的短距离非接触智慧卡的功能及运作标准,使用的频率为13.56MHz.     ISO14443定义了TYPE ...

  6. C#使用系统的“显示桌面”功能(Shell.Application)

    原文 C#使用系统的“显示桌面”功能(Shell.Application) 在 Windows 系统的 任务栏 上的 快速启动栏 里,通常有一个图标  ,点击这个图标,就会切换到桌面.这个图标实际是一 ...

  7. Spring Boot Admin Reference Guide

    1. What is Spring Boot Admin? Spring Boot Admin is a simple application to manage and monitor your S ...

  8. HDU 1091 A+B for Input-Output Practice (III)

    #include <cstdio> int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) if ( ...

  9. HDU 2501 Tiling_easy version

    递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...

  10. HDU 1131 Count the Trees

    卡特兰数再乘上n的阶乘 #include<iostream> #include<cstdio> using namespace std; #define base 10000 ...