题意描述

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的更多相关文章

  1. POJ1840: Eqs(hash问题)

    一道典型的hash问题: 已知a1,a2,a3,a4,a5,求有多少种不同的<x1,x2,x3,x4,x5>组合满足等式: a1*x1^3 + a2*x2^3 + a3*x3^3 + a4 ...

  2. poj1840 Eqs(hash+折半枚举)

    Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...

  3. POJ 1840 Eqs

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15010   Accepted: 7366 Description ...

  4. Eqs

    Eqs 题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15029 题意: 给出系数a1,a2,a3,a4,a5,求出 ...

  5. POJ1840 hash

    POJ1840 问题重述: 给定系数a1,a2, ..,a5,求满足a1 * x1 ^ 3 + a2 * x2 ^ 3 +... + a5 * x5 ^ 3 = 0的 xi 的组数.其中ai, xi都 ...

  6. 【POJ】1840:Eqs【哈希表】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18299   Accepted: 8933 Description ...

  7. 測试赛C - Eqs(哈希)

    C - Eqs Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  8. poj1840

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15133   Accepted: 7426 Description ...

  9. POJ-1840 Eqs---二分

    题目链接: https://vjudge.net/problem/POJ-1840 题目大意: 给出一个5元3次方程,输入其5个系数,求它的解的个数 其中系数 ai∈[-50,50]  自变量xi∈[ ...

随机推荐

  1. Python-读写csv数据模块 csv

    案例: 通过股票网站,我们获取了中国股市数据集,它以csv数据格式存储 Data,Open,High,Low,Close,Volume,Adj Close 2016-06-28,8.63,8.47,8 ...

  2. 烽火服务器IPMI远程装机

    连接控制台 一.通过vpn拨入进入内网,使用IE浏览器或者火狐等等,连接ilo地址.(需要安装java8.0,各个品牌的服务器需要的不一样) 二.启动虚拟连接控制台,进行控制主机 三.根据截图进行操作 ...

  3. windows.h系统函数

    转载:https://blog.csdn.net/u010756046/article/details/82432312 // Windows系统函数.cpp: 定义控制台应用程序的入口点.// #i ...

  4. The Python Tutorial 和 documentation和安装库lib步骤

    链接: The Python Tutorial : https://docs.python.org/3.6/tutorial/index.html Documentation: https://doc ...

  5. SPI应用 用SPI控制一个数字电位器

    Controlling a Digital Potentiometer Using SPI In this tutorial you will learn how to control the AD5 ...

  6. 第2天 | 12天搞定Python,运行环境(超详细步骤)

    倘若有人告诉你,他在学习Python编程,却没有安装运行环境,那你赶紧叫他滚,并离他远点,因为他在欺骗你的感情. 没有安装运行环境,程序根本无法跑起来,对错不能知根知底,试问是在学编程,还是在跟空气对 ...

  7. Oracle 正确删除归档日志的方法

    我们都知道在controlfile中记录着每一个archivelog文件的相关信息,当然们在OS下把这些物理文件delete掉后,在我们的controlfile中仍然记录着这些archivelog文件 ...

  8. CyclicBarrier原来是这样的

    上一篇聊了一下Semaphore信号灯的用法及源码,这一篇来聊一下CyclicBarrier的用法及解析. 官网解释: 允许一组线程全部等待彼此达到共同屏障点的同步辅助.循环阻塞在涉及固定大小的线程方 ...

  9. springMvc配置拦截器无效

    说明 springMvc配置国际化拦截器失败,点击页面按钮切换中英文无效,排查发现没有进入 LocaleChangeInterceptor 类中,判断拦截器没有起作用,那么是什么原因导致拦截器无效,通 ...

  10. beego log

    package main import ( "github.com/astaxie/beego/logs" _ "xcms/routers" _ "x ...