当前位置:网站首页>求解多元多次方程解的个数
求解多元多次方程解的个数
2022-08-01 21:35:00 【chengqiuming】
一 原问题链接
二 输入和输出
1 输入
2 输出
三 输入和输出样例
1 输入样例
37 29 41 43 47
2 输出样例
654
四 分析和设计
= 0 变化为
= -(
), 这样就可以从 5 层循环变为 3 层循环。将等式左或右的值暴力枚举并存入哈希表,由于可能存在负值,所以让负值+25000000 转化为正数,并且保证数值的唯一性。再暴力枚举等式的另一边。将哈希表对应的值直接存在 ans 累加器,最后输出 ans。 五 代码
package poj1840;
import java.util.Scanner;
public class POJ1840 {
static int maxn = 25000000 + 10;
// 数组太大,不能用int(int型数组1677w左右),用short型数组
static short hash[] = new short[maxn];
static int a1, a2, a3, a4, a5;
public static void main(String[] args) {
int ans, temp;
Scanner scanner = new Scanner(System.in);
a1 = scanner.nextInt();
a2 = scanner.nextInt();
a3 = scanner.nextInt();
a4 = scanner.nextInt();
a5 = scanner.nextInt();
ans = 0;
for (int i = -50; i <= 50; i++)
for (int j = -50; j <= 50; j++) {
if (i == 0 || j == 0) continue;
temp = (a1 * i * i * i + a2 * j * j * j) * (-1);
if (temp < 0)
temp = temp + maxn;
hash[temp]++;
}
for (int i = -50; i <= 50; i++)
for (int j = -50; j <= 50; j++)
for (int k = -50; k <= 50; k++) {
if (i == 0 || j == 0 || k == 0) continue;
temp = a3 * i * i * i + a4 * j * j * j + a5 * k * k * k;
if (temp < 0)
temp = temp + maxn;
if (hash[temp] > 0)
ans = ans + hash[temp];
}
System.out.println(ans);
}
}六 测试

边栏推荐
- Small program -- subcontracting
- 宝塔应用使用心得
- WEB 渗透之文件类操作
- C语言必杀技3行代码把运行速度提升4倍
- [@synthesize in Objective-C]
- C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.1 The Prehistoric Phase of the C Language
- File operations of WEB penetration
- 方舟生存进化是什么游戏?好不好玩
- C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.5 ANSI C Today
- Scala练习题+答案
猜你喜欢

Homework 8.1 Orphans and Zombies

RecycleView的使用

【Jmeter常用断言组件】

Chapter 12, target recognition of digital image processing

基于php影视资讯网站管理系统获取(php毕业设计)

ARFoundation Getting Started Tutorial U2-AR Scene Screenshot Screenshot

【力扣】字符串相乘

C expert programming

HCIP---Multiple Spanning Tree Protocol related knowledge points

groupByKey和reduceBykey的区别
随机推荐
File operations of WEB penetration
51.【结构体初始化的两种方法】
HCIP---企业网的架构
【C语言实现】最大公约数的3种求法
ImportError: `save_weights` requires h5py.问题解决
数据库练习
ORI-GB-NP半乳糖介导冬凌草甲素/姜黄素牛血清白蛋白纳米粒的研究制备方法
Centos7--MySQL的安装
HCIP---Architecture of Enterprise Network
回收租凭系统100%开源无加密 商城+回收+租赁
C Expert Programming Preface
RecycleView的使用
Based on php online learning platform management system acquisition (php graduation design)
C pitfalls and pitfalls Chapter 8 Suggestions and answers 8.2 Answers
Pytest: begin to use
FusionGAN:A generative adversarial network for infrared and visible image fusion文章学习笔记
C语言_枚举类型介绍
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.2 Early Experience of C Language
【Objective-C中的@synthesize】
MySQL相关知识