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 ;
}

最新文章

  1. Mongodb学习笔记四(Mongodb聚合函数)
  2. 利用.net的内部机制在asp.net中实现身份验证
  3. MySql5.7-多源复制(多主单从)
  4. Android无法连接adb的解决方法
  5. 三、nginx实现反向代理负载均衡
  6. svg从入门到装逼(一)
  7. Python——类的封装
  8. [Swift]LeetCode825. 适龄的朋友 | Friends Of Appropriate Ages
  9. docker~在centos容器中安装新程序
  10. 利用python脚本(xpath)抓取数据
  11. 个人作业四--Alpha阶段个人总结
  12. google浏览器window.onbeforeunload方法兼容问题
  13. Java之资源文件读取
  14. lambda expressions are not supported at this language level
  15. js indexOf within Switch
  16. dvwa学习笔记之xss
  17. day04作业
  18. Asp.net Vnext 实现IView
  19. el表达式 多条件判断
  20. Mongodb 命令及 PyMongo 库的使用

热门文章

  1. 【sqli-labs】 less48 GET -Error based -Blind -Numeric -Order By Clause(GET型基于盲注的整型Order By从句注入)
  2. mysql异地备份方案经验总结
  3. Laravel实用小功能
  4. vue 项目的I18n国际化之路
  5. Problem 28
  6. hdu 5652
  7. mac上常用的命令
  8. 【Codeforces 466C】Number of Ways
  9. 【codeforces 767A】Snacktower
  10. JavaSE 学习笔记之String字符串(十四)