HDU - 1496 Equations (hash)
题意:
多组测试数据。
每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且都不为0。
给定a, b, c, d ∈ [-50, 50] ,且都不为0, 求上述条件下方程解的个数。
比赛的时候想到的是枚举三个,另一个可以直接算出来。但是一直TLE。。。结果就没做出来。
看了题解,用的hash,很巧妙。结果自己用map写还是T。。最后用数组写的。 _φ(❐_❐✧
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define maxn 1000000 int hsh[*maxn+];
int main()
{
int a, b, c, d;
while(~scanf("%d%d%d%d", &a, &b, &c, &d))
{
int ans = ;
memset(hsh, , sizeof(hsh)); for (int x1 = ; x1 <= ; x1++)
for (int x2 = ; x2 <= ; x2++)
hsh[maxn + x1*x1*a + x2*x2*b]++; for (int x3 = ; x3 <= ; x3++)
for (int x4 = ; x4 <= ; x4++)
ans += hsh[maxn - (x3*x3*c + x4*x4*d)]; printf("%d\n", ans*);
}
}
HDU - 1496 Equations (hash)的更多相关文章
- HDU 1496 Equations(哈希表)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1496 [题目大意] 给出一个方程ax1^2+bx2^2+cx3^2+dx4^2=0,求-100到1 ...
- HDU 1840 Equations (数学)
title: Equations 数学 杭电1840 tags: [数学] 题目链接 Problem Description All the problems in this contest tota ...
- HDU 4821 String (HASH)
题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字, ...
- HDU 2523 sort (hash)
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 哈希(Hash)与加密(Encrypt)相关内容
1.哈希(Hash)与加密(Encrypt)的区别 哈希(Hash)是将目标文本转换成具有相同长度的.不可逆的杂凑字符串(或叫做消息摘要),而加密(Encrypt)是将目标文本转换成具有不同长度的.可 ...
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- tomcat7 fail to start inside Ubuntu Docker container
The tomcat startup script needs some special privileges. Concrete it needs to check all running proc ...
- feign客户端传参数报错
新手经常遇到的错误 Caused by: java.lang.IllegalStateException: Method has too many Body parameters feign多参数问题 ...
- c# 字符串的首字母大写转换 方法
方法1: s.Substring(0,1).ToUpper()+s.Substring(1); 方法2: s = System.Threading.Thread.CurrentThread.Curr ...
- css3的过渡、动画、2D、3D效果
浏览器的内核: 谷歌的内核是:webkit 火狐的内核是:gecko Ie的内核是:trident 欧鹏的内核是:presto 国内浏览器的内核:webkit css3针对同一样式在不同的浏览器的兼容 ...
- 初学Vue.js(2.x版本)
首先肯定是打开官网查看文档了,没想到我太高估了自己,看的我头晕也不知道到底说了个啥.没办法,只能另寻他法,好在有菜鸟教程.然而我还是想多了,不稀饭一点点看下去,只想快点明白它到底说了个啥.嗯,找来找去 ...
- css 居中问题总结
html代码: <div class="box"> <div class="box-item"> 文字 </div> < ...
- mui页面间传接值例子
传值页面index.html <!DOCTYPE html><html><head> <meta charset="utf-8"> ...
- BUG严重级别定义及注意事项
- 首次将项目从svn下载到eclipse
1.点击 File --> Import,进入导入项目窗口 2.选择从SVN检出项目,点击Next 3.选择创建新的资源库位置,点击Next 4.在URL处输入SVN项目远程地址,点击Next ...
- js进阶之function对象
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...