当前位置:网站首页>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

边栏推荐
猜你喜欢

方舟生存进化是什么游戏?好不好玩

Based on php online examination management system acquisition (php graduation design)

C expert programming

基于php旅游网站管理系统获取(php毕业设计)

上传markdown文档到博客园

ImportError: `save_weights` requires h5py. Problem solved

用户体验 | 如何度量用户体验?

ARFoundation入门教程U2-AR场景截图截屏

Shell编程之条件语句

Chapter 12, target recognition of digital image processing
随机推荐
LeetCode952三部曲之一:解题思路和初级解法(137ms,超39%)
Spark shuffle tuning
基于php动漫周边商城管理系统(php毕业设计)
Dichotomy Medium LeetCode6133. Maximum Number of Groups
多商户商城系统功能拆解19讲-平台端发票管理
AIDL communication
小程序--分包
WEB 渗透之端口协议
shell编程规范与变量
Pytest: begin to use
游戏元宇宙发展趋势展望分析
Based on php online examination management system acquisition (php graduation design)
一个关于操作数据库的建议—用户密码
【移动Web】移动端适配
【C语言实现】整数排序-四种方法,你都会了吗、
scikit-learn no moudule named six
基于php旅游网站管理系统获取(php毕业设计)
基于php在线音乐网站管理系统获取(php毕业设计)
Unity Shader 常规光照模型代码整理
树莓派的信息显示小屏幕,显示时间、IP地址、CPU信息、内存信息(c语言),四线的i2c通信,0.96寸oled屏幕