POJ1840 Eqs
题意描述
求一个五元方程 \(a_1x_1^3+a_2x_2^3+a_3x_3^3+a_4x_4^3+a_5x_5^3=0\) 的解的个数。
题中给出 \(a_i\) 的值并且保证 \(-50\leq a_i,x_i\leq 50,x_i\neq 0\)。(\(1\leq i\leq 5\))
算法分析
考虑暴力枚举,发现复杂度 \(100^5=10^{10}\),T 到飞起。
移项后变为:\(a_1x_1^3+a_2x_2^3+a_3x_3^3=-(a_4x_4^3+a_5x_5^3)\)。
可以考虑分两次枚举等式两边的值,通过 Hash 判断是否相等即可。
真·神仙思路。
代码实现
注意卡常啊,STL 的 vector/map 用不得。
这里不能判重哦,相等的也要加进去。(肯定是不同情况)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define N 100010
#define M 6000010
#define MOD 99991
using namespace std;
int a1,a2,a3,a4,a5,head[N],cnt=0;
struct Edge{
int nxt,to;
}ed[M];
int read(){
int x=0,f=1;char c=getchar();
while(c<'0' || c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0' && c<='9') x=x*10+c-48,c=getchar();
return x*f;
}
void init(){
a1=read(),a2=read(),a3=read(),a4=read(),a5=read();
return;
}
int Abs(int x){
return x>0?x:-x;
}
void insert(int x){
int p=Abs(x)%MOD;
ed[++cnt].nxt=head[p];
ed[cnt].to=x;
head[p]=cnt;
return;
}
void pre_work(){
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;
int now=a1*i*i*i+a2*j*j*j+a3*k*k*k;
insert(now);
}
return;
}
int search(int now){
int p=Abs(now)%MOD,sum=0;
for(int i=head[p];i;i=ed[i].nxt)
if(now==ed[i].to) sum++;
return sum;
}
int main(){
init();
pre_work();
long long ans=0;
for(int i=-50;i<=50;i++)
for(int j=-50;j<=50;j++){
if(i==0 || j==0) continue;
int now=a4*i*i*i+a5*j*j*j;
ans+=search(-now);
}
printf("%d\n",ans);
return 0;
}
完结撒❀。
POJ1840 Eqs的更多相关文章
- POJ1840: Eqs(hash问题)
一道典型的hash问题: 已知a1,a2,a3,a4,a5,求有多少种不同的<x1,x2,x3,x4,x5>组合满足等式: a1*x1^3 + a2*x2^3 + a3*x3^3 + a4 ...
- poj1840 Eqs(hash+折半枚举)
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 Description ...
- Eqs
Eqs 题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15029 题意: 给出系数a1,a2,a3,a4,a5,求出 ...
- POJ1840 hash
POJ1840 问题重述: 给定系数a1,a2, ..,a5,求满足a1 * x1 ^ 3 + a2 * x2 ^ 3 +... + a5 * x5 ^ 3 = 0的 xi 的组数.其中ai, xi都 ...
- 【POJ】1840:Eqs【哈希表】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18299 Accepted: 8933 Description ...
- 測试赛C - Eqs(哈希)
C - Eqs Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj1840
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15133 Accepted: 7426 Description ...
- POJ-1840 Eqs---二分
题目链接: https://vjudge.net/problem/POJ-1840 题目大意: 给出一个5元3次方程,输入其5个系数,求它的解的个数 其中系数 ai∈[-50,50] 自变量xi∈[ ...
随机推荐
- Python字符编码和二进制不得不说的故事
二进制 核心思想: 冯诺依曼 + 图灵机 电如何表示状态,才能稳定? 计算机开始设计的时候并不是考虑简单,而是考虑能自动完成任务与结果的可靠性, 简单始终是建立再稳定.可靠基础上 经过尝试10进制,但 ...
- 05 sublime环境配置及编译运行后输出中文乱码的解决
编译后的乱码问题 编译后的输出:中文显示异常: 编译C出现乱码问题解决 解决思路:解决办法很简单,就是先设置文件编码为GBK格式,之后再输入中文文字,运行时的中文就不是乱码了. 首先,sublime中 ...
- 文档生成工具——Doxygen
参考: 1.https://blog.csdn.net/liao20081228/article/details/77322584 2.https://blog.csdn.net/wang150619 ...
- 利用TfidfVectorizer进行中文文本分类(数据集是复旦中文语料)
1.对语料进行分析 基本目录如下: 其中train存放的是训练集,answer存放的是测试集,具体看下train中的文件: 下面有20个文件夹,对应着20个类,我们继续看下其中的文件,以C3-Art为 ...
- 萌新学python
python python安装 进入官网http://www.python.org/download/ 下载 我下的是3.6.6大家可以根据需要下载(3.x和2.x不兼容请小心) 之后安装就可以了 p ...
- linux 中 eclipse 开发 c/c++ 多线程程序,添加 libpthread.a 库支持
导入头文件 在 linux 中开发多线程程序,在使用到 pthread 系列函数的文件中,需要导入头文件: #include <pthread.h> 链接 libpthread.a 在编译 ...
- devops工具链概述
1. devops工具链概述 1)devops工具篇 2) 持续集成 3) 持续交付 4) 持续部署 2. devops工具链概述
- TTL电平,CMOS电平,232/485电平,OC门,OD门基础知识
1.RS232电平 或者说串口电平,有的甚至说计算机电平,所有的这些说法,指得都是计算机9针串口 (RS232)的电平,采用负逻辑, -15v ~ -3v 代表1 +3v ~ +15v 代表0 2. ...
- Request对象基础应用实例代码一
输入用户名:<br><input type="text" name="yhm"><br><br>输入密码:< ...
- 发布MeteoInfo 1.2.3
提升了对GeoTiff格式数据的读取能力(多个tiles).当然还有MeteoInfoLab功能的提升.下载地址:http://yun.baidu.com/share/link?shareid=669 ...