Eqs(枚举+ hash)
2024-08-31 02:43:23
http://poj.org/problem?id=1840
题意:给出系数a1,a2,a3,a4,a5,求满足方程的解有多少组。
思路:有a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 可得 -(a1x13+ a2x23) = a3x33+ a4x43+ a5x53;
先枚举x1,x2,用hash[]记录 sum出现的次数,然后枚举后三个点,若左边出现的sum在右边可以找到,那么hash[sum]即为解的个数。
#include <cstdio>
#include <string.h>
#include <iostream>
#define N 25000000
using namespace std;
short hash[N+]; int main()
{
int a1,a2,a3,a4,a5;
while(cin>>a1>>a2>>a3>>a4>>a5)
{
int x1,x2,x3,x4,x5;
int ans = ;
memset(hash,,sizeof(hash));
for (x1 = -; x1 <= ; x1 ++)
{
if(!x1) continue;
for (x2 = -; x2 <= ; x2 ++)
{
if (!x2) continue;
int sum =(a1*x1*x1*x1+a2*x2*x2*x2)*(-);
if (sum < )
sum += N;
hash[sum]++; }
}
for (x3 = -; x3 <= ; x3 ++)
{
if(!x3) continue;
for (x4 = -; x4 <= ; x4 ++)
{
if (!x4) continue;
for (x5 = -; x5 <= ; x5 ++)
{
if (!x5) continue;
int sum = a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if (sum < )
sum += N;
if (hash[sum])
ans += hash[sum];
}
}
}
cout<<ans<<endl;
}
return ;
}
最新文章
- Mongodb学习笔记四(Mongodb聚合函数)
- 利用.net的内部机制在asp.net中实现身份验证
- MySql5.7-多源复制(多主单从)
- Android无法连接adb的解决方法
- 三、nginx实现反向代理负载均衡
- svg从入门到装逼(一)
- Python——类的封装
- [Swift]LeetCode825. 适龄的朋友 | Friends Of Appropriate Ages
- docker~在centos容器中安装新程序
- 利用python脚本(xpath)抓取数据
- 个人作业四--Alpha阶段个人总结
- google浏览器window.onbeforeunload方法兼容问题
- Java之资源文件读取
- lambda expressions are not supported at this language level
- js indexOf within Switch
- dvwa学习笔记之xss
- day04作业
- Asp.net Vnext 实现IView
- el表达式 多条件判断
- Mongodb 命令及 PyMongo 库的使用