[Swust OJ 166]--方程的解数(hash法)
题目链接:http://acm.swust.edu.cn/problem/0166/
有如下方程组: A1*x1^3+A2*x2^3+A3*x3^3+A4*x4^3+A5*x5^3=0,其中A1…A5都在[-50,50]内。 如果(x1,x2,x3,x4,x5)(其中-50<=xi<=50,xi!=0)能让该等式成立,就说(x1,x2,x3,x4,x5)为其一组解,现在的问题是要问你该等式共有多少组解。
输入包括5个系数 A1,A2,A3,A4,A5
注意:这里是多组输入哈,太坑爹了!
输出该方程解的数目
1
|
23 45 36 13 57
|
1
|
1436
|
- #include <stdio.h>
- #include <string.h>
- #define maxn 25000010
- short hash[maxn];
- int main(){
- int a[], x1, x2, x3, x4, x5, cnt, temp;
- while (scanf("%d%d%d%d%d", &a[], &a[], &a[], &a[], &a[]) != EOF){
- cnt = ;
- memset(hash, , sizeof(hash));
- for (x1 = -; x1 <= ; x1++){
- if (x1){
- for (x2 = -; x2 <= ; x2++){
- if (x2){
- temp = a[] * x1*x1*x1 + a[] * x2*x2*x2;
- if (temp<)
- temp += maxn;
- hash[temp]++;
- }
- }
- }
- }
- for (x3 = -; x3 <= ; x3++){
- if (x3){
- for (x4 = -; x4 <= ; x4++){
- if (x4){
- for (x5 = -; x5 <= ; x5++){
- if (x5){
- temp = -(a[] * x3*x3*x3 + a[] * x4*x4*x4 + a[] * x5*x5*x5);
- if (temp<)
- temp += maxn;
- if (hash[temp])
- cnt += hash[temp];
- }
- }
- }
- }
- }
- }
- printf("%d\n", cnt);
- }
- return ;
- }
但是发现有人低内存ac了,然后,然后,把每次求得的值MOD一个数,然后~~~(智商啊)
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #define maxn 200005
- int hash[maxn][], num[maxn];
- int main(){
- int i, j, k, l, cnt, tmp, mark, a[];
- while (~scanf("%d%d%d%d%d", &a[], &a[], &a[], &a[], &a[])){
- memset(num, , sizeof(num));
- cnt = ;
- for (i = -; i <= ; i++){
- if (i){
- for (j = -; j <= ; j++){
- if (j){
- tmp = a[] * i*i*i + a[] * j*j*j;
- mark = abs(tmp) % maxn;
- hash[mark][num[mark]] = tmp;
- num[mark]++;
- }
- }
- }
- }
- for (i = -; i <= ; i++){
- if (i){
- for (j = -; j <= ; j++){
- if (j){
- for (k = -; k <= ; k++){
- if (k){
- tmp = a[] * i*i*i + a[] * j*j*j + a[] * k*k*k;
- mark = abs(tmp) % maxn;
- for (l = ; l < num[mark]; l++)
- if (tmp == hash[mark][l]) cnt++;
- }
- }
- }
- }
- }
- }
- printf("%d\n", cnt);
- }
- return ;
- }
[Swust OJ 166]--方程的解数(hash法)的更多相关文章
- POJ 1186 方程的解数
方程的解数 Time Limit: 15000MS Memory Limit: 128000K Total Submissions: 6188 Accepted: 2127 Case Time ...
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- NOI2001 方程的解数
1735 方程的解数 http://codevs.cn/problem/1735/ 2001年NOI全国竞赛 时间限制: 5 s 空间限制: 64000 KB 题目描述 Descripti ...
- cogs 304. [NOI2001] 方程的解数(meet in the middle)
304. [NOI2001] 方程的解数 ★★☆ 输入文件:equation1.in 输出文件:equation1.out 简单对比时间限制:3 s 内存限制:64 MB 问题描述 已 ...
- P5691 [NOI2001]方程的解数
题意描述 方程的解数 求方程 \(\sum_{i=1}^{n}k_ix_i^{p_i}=0(x_i\in [1,m])\) 的解的个数. 算法分析 远古 NOI 的题目就是水 类似于这道题. 做过这道 ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- 计蒜客 方程的解数 dfs
题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...
- [ NOI 2001 ] 方程的解数
\(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...
- NTC热敏电阻温度计算方法,Steinhart-Hart方程和B值法(转)
NTC热敏电阻计算器使用方法 NTC热敏电阻计算器 V1.0 10K负温度系数热敏电阻(NTC)温度与阻值对应关系表 Rt = R(25℃)*EXP[B*(1/T - 1/(T+25))] 说明: 1 ...
随机推荐
- JS 引用
var arr1=[1,2,3,4]; var arr2=arr1; arr2.push(5); console.log(arr1);//和arr2一样 console.log(arr1==arr2) ...
- Bootstrap 响应式瀑布流 (使用wookmark)
使用瀑布布局 官方 http://www.wookmark.com/jquery-plugin GitHub https://github.com/GBKS/Wookmark-jQuery (下载后 ...
- 关于LD_DEBUG (转载)
引用 LD_DEBUGThe dynamic library loader used in linux (part of glibc) has some neat tricks. One of the ...
- 记NOIP分数出来前
咩~成绩还没有出来呢!但是拿到了每个人的程序,还有一堆民间的数据.我测了好多不同的数据,基本上D1T1,D2T1,D2T2的都是暴力解决掉的,没有什么问题,唯一就是D1T2的link那一题,写的时候2 ...
- makinacorpus/spynner
makinacorpus/spynner Intro Contents Intro Credits Companies Authors Contributors Dependencies Feedba ...
- Silverlight CheckBoxList
项目要用到复选框,可是在Silverlight中不存在CheckBoxList.通过查阅资料以及依据自己的理解,写了简单演示样例: 1.XAML <UserControl x:Class=&qu ...
- C++ Primer的课后规划问题的第八章
1.写通常需要一个参数(字符串的地址).字符串和打印功能. 只要.假设提供了第二个参数(int种类),而这个参数不0,的次数的函数打印串数量为该功能将被称为(意,字符串的打印次数不等于第二个參数的值. ...
- .net 常用方法
1.String数组转换成Int数组 string[] strArr = "a,b,c".Split(','); int[] intArr = Array.ConvertAll& ...
- Port 8081 already in use, packager is either not running or not running correctly
运行 react_native 时发生这个错误,解决办法 关掉端口8081对应的进程 1.打开终端,输入命令:lsof -i:8081 2.此时提示: COMMAND PID USER ...
- C++之对象组合
#include<stdio.h>//初始化列表 提供了对成员变量初始化的方式//Constructor class M { private: ...