当前位置:网站首页>number of solutions to solve a multivariate multi-degree equation
number of solutions to solve a multivariate multi-degree equation
2022-08-01 21:47:00 【Chengqiuming】
A link to the original question
Two Inputs and Outputs
1 input
2 output
Three input and output samples
1 Input example
37 29 41 43 47
2 Sample output
654
Four Analysis and Design
= 0 changes to
= -(
), This will change from a 5-layer loop to a 3-layer loop.The left or right values of the equation are violently enumerated and stored in the hash table. Since there may be negative values, let the negative value +25000000 be converted into a positive number, and the uniqueness of the value is guaranteed.Then brute force the other side of the equation.Store the value corresponding to the hash table directly in the ans accumulator, and finally output ans.Five codes
package poj1840;import java.util.Scanner;public class POJ1840 {static int maxn = 25000000 + 10;// The array is too large to use int (about 1677w for int array), use short arraystatic 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);}}Six Tests

边栏推荐
猜你喜欢

WEB渗透之SQL 注入

树莓派的信息显示小屏幕,显示时间、IP地址、CPU信息、内存信息(c语言),四线的i2c通信,0.96寸oled屏幕

NFT的10种实际用途(NFT系统开发)

LVS负载均衡群集

恒星的正方形问题

方舟开服需要知道的那些事

365天挑战LeetCode1000题——Day 046 生成每种字符都是奇数个的字符串 + 两数相加 + 有效的括号

Anacoda的用途

Based on php tourism website management system acquisition (php graduation design)

Based on php Xiangxi tourism website management system acquisition (php graduation design)
随机推荐
Shell programming conditional statement
基于php在线学习平台管理系统获取(php毕业设计)
The thing about npm
【ASM】字节码操作 MethodWriter
Anacoda的用途
Based on php hotel online reservation management system acquisition (php graduation project)
Based on php online examination management system acquisition (php graduation design)
Appendix A printf, varargs and stdarg a. 2 use varargs. H to realize the variable argument list
FusionGAN:A generative adversarial network for infrared and visible image fusion文章学习笔记
Spark cluster construction
越长大越孤单
”sed“ shell脚本三剑客
Based on php tourism website management system acquisition (php graduation design)
模拟数据之mockjs
还在纠结报表工具的选型么?来看看这个
[@synthesize in Objective-C]
Unity Shader general lighting model code finishing
Raspberry Pi information display small screen, display time, IP address, CPU information, memory information (C language), four-wire i2c communication, 0.96-inch oled screen
SOM网络1:原理讲解
2022 版 MySQL 巅峰教程,收藏好,慢慢看