[Swust OJ 166]--方程的解数(hash法)
题目链接:http://acm.swust.edu.cn/problem/0166/
有如下方程组: 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)为其一组解,现在的问题是要问你该等式共有多少组解。
输入包括5个系数 A1,A2,A3,A4,A5
注意:这里是多组输入哈,太坑爹了!
输出该方程解的数目
|
1
|
23 45 36 13 57
|
|
1
|
1436
|
#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法)的更多相关文章
- POJ 1186 方程的解数
方程的解数 Time Limit: 15000MS Memory Limit: 128000K Total Submissions: 6188 Accepted: 2127 Case Time ...
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- NOI2001 方程的解数
1735 方程的解数 http://codevs.cn/problem/1735/ 2001年NOI全国竞赛 时间限制: 5 s 空间限制: 64000 KB 题目描述 Descripti ...
- cogs 304. [NOI2001] 方程的解数(meet in the middle)
304. [NOI2001] 方程的解数 ★★☆ 输入文件:equation1.in 输出文件:equation1.out 简单对比时间限制:3 s 内存限制:64 MB 问题描述 已 ...
- P5691 [NOI2001]方程的解数
题意描述 方程的解数 求方程 \(\sum_{i=1}^{n}k_ix_i^{p_i}=0(x_i\in [1,m])\) 的解的个数. 算法分析 远古 NOI 的题目就是水 类似于这道题. 做过这道 ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- 计蒜客 方程的解数 dfs
题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...
- [ NOI 2001 ] 方程的解数
\(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...
- NTC热敏电阻温度计算方法,Steinhart-Hart方程和B值法(转)
NTC热敏电阻计算器使用方法 NTC热敏电阻计算器 V1.0 10K负温度系数热敏电阻(NTC)温度与阻值对应关系表 Rt = R(25℃)*EXP[B*(1/T - 1/(T+25))] 说明: 1 ...
随机推荐
- C#读取网页
public bool getweb(string strURL,out string buf) { buf=""; try { //Uri url=new Uri(strURL, ...
- 定时每天备份mysql
http://blog.csdn.net/panning_hu/article/details/9210001 Spring MVC Spring中MVC框架的底层实现 http://blog.csd ...
- 精简版LVCL,有空看看
http://tothpaul.free.fr/sources.php?lvcl.lvcl1 http://synopse.info/forum/viewtopic.php?id=665
- HDU 3802 Ipad,IPhone
http://wutyyzchangde.blog.163.com/blog/static/172226566201132311311374/ #include <cstdio> type ...
- JAVA GUI学习 - JTree树结构组件学习 ***
public class JTreeKnow extends JFrame { public JTreeKnow() { this.setBounds(300, 100, 400, 500); thi ...
- java学习之jdbc的封装
jdbc是连接数据库必不可少的工具,但每次连接都要重新写一遍太麻烦了,也不利于代码的可读性,这里做一个工具类进行封装. package com.gh; import java.sql.Connecti ...
- HDU - 2276 Kiki & Little Kiki 2
Description There are n lights in a circle numbered from 1 to n. The left of light 1 is light n, and ...
- 去掉word2007回车后自动编号
1. 在使用word自动编号时,回车续写上一编号内容可能会行距很宽,这时候使用shift+回车不会自动下一编号,而且是正常行距 取消回车自动编号: 打开Word文档,单击菜单栏上的[格式]→[自动套用 ...
- django1.6.x(python3.3)使用pymysql连接mysql
1.安装 pymysql,地址:https://code.google.com/p/pymysql/ 2.安装django 然后执行 django-admin.py startproject mysi ...
- commons-logging \ log4j \ slf4j 之间的关系
最近的一个web项目中要使用到日志,但是对常用的日志记录工具(框架)着实不是很理解,在此mark一下. 1.commons-logging.jar common-logging是apache提供的一个 ...