经典hash. POJ 1840
来源:互联网 发布:乐呵棋牌全套完整源码 编辑:程序博客网 时间:2024/06/05 23:49
这道题真是有着不堪回首的过去。。
那是。。。。成都之后还是之前,决定是否去杭州的一场和小朋友的“友谊赛”。。
一开始延续了当时的思路。。但是还是T,使用mod的 hash 时间复杂度还是不够。
不过幸好由于数字比较小,杀手锏直接开个大数组记录答案的个数。
前两个变量一组,后三个变量一组,速度还挺快。
不过数组用char来开就足够了,用int开的话会MLE。
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <vector>#include <map>#include <assert.h>using namespace std;const int MAX = 12500000;int coef[10];char sum[MAX*3+1];//25 000 000int cube(int a){ return a*a*a;}int myback(int i,int j,int k){ return -(coef[2]*cube(i)+coef[3]*cube(j)+coef[4]*cube(k));}int myfront(int i,int j){ return coef[0]*cube(i)+coef[1]*cube(j);}int main(){ freopen("acm.in","r",stdin); while(scanf("%d",&coef[0])!=EOF) { memset(sum,0,sizeof(sum)); for(int i=1;i<=4;i++) scanf("%d",&coef[i]); for(int i=-50;i<=50;i++) { if(i!=0) for(int j=-50;j<=50;j++) { if(j!=0) { int t=myfront(i,j)+MAX; sum[t]++; } } } int ans=0; for(int i=-50;i<=50;i++) { if(i!=0) for(int j=-50;j<=50;j++) { if(j!=0) for(int k=-50;k<=50;k++) { if(k!=0) { int t=myback(i,j,k)+MAX; if(t>=0&&t<=MAX*2) ans+=sum[t]; } } } } printf("%d\n",ans); } return 0;}
0 0
- 经典hash. POJ 1840
- poj 1840 简单hash。
- POJ 1840 Eqs hash
- POJ-1840 Eqs【Hash】
- poj 1840 Eqs 【hash】
- POJ 1840 (hash)
- poj 1840 (hash)
- POJ 1840 hash
- poj 1840 Eqs , hash
- POJ 1840 Eqs(hash)
- POJ 1840 Eqs(hash)
- poj 1840 简单hash
- POJ 1840 Eqs (hash)
- POJ-1840 Eqs Hash
- POJ 1840 HASH
- poj 1840 Eqs hash
- poj 1840 Eqs(Hash)
- poj 1840hash
- Groovy中的Actor模型
- 文献笔记 《AndroTotal : A Flexible, Scalable Toolbox and Service for Testing Mobile Malware Detectors》
- (七)Spring2.5中Bean的初始化与销毁(bean_init_destroy)主要是对Bean为单例的情况
- [Python]How to use magic methods in Python?
- Linux 使用札记(一) 硬盘安装Ubuntu 11.04
- 经典hash. POJ 1840
- 买房子要交哪些税
- 2013.12.27 switch、break、continue
- 第一天
- 求一个数的余数 用取模函数%和移位操作思路的分析
- Auto Mass Traffic Generation Software
- 如何使用cuMemGetInfo函数
- 2013.12.27 泡面吧--简单的斐波那契数列
- Gartner 认可 Microsoft 为应用程序平台即服务的领导者