SPOJ:ABCDEF
废话不说,这道题暴力枚举是$O(N^6)$,显然无法承受。
推导一下
$(x_1*x_2+x_3)/x_4-x_5=x_6$
$x_1*x_2+x_3=x_4*(x_5+x_6)$
等式左边和右边的复杂度都是$O(N^3)$的,可以接受!
但是如果没开$O_2$不要用map,会被卡常,g++11的unorderded_map不错,但是大部分OJ并不滋次,建议手写hash,based要卡大点。
//OJ 1869
//by Cydiater
//2016.9.13
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define ll long long
#define up(i,j,n) for(ll i=j;i<=n;i++)
#define down(i,j,n) for(ll i=j;i>=n;i--)
const ll oo=0x3f3f3f3f;
;
;
inline ll read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
ll lable[];
ll N,a[],ans=;
struct HashTable{
ll Value[];
HashTable(){up(i,,mod+)Value[i]=-oo;}
ll Hash_value(ll num){
ll tmp=num;
num%=mod;num+=mod;num%=mod;
while(Value[num]!=tmp){
if(Value[num]==-oo){
Value[num]=tmp;
return num;
}
num+=step;num%=mod;
}
return num;
}
}hash;
namespace solution{
void pret(){
up(i,,N)up(j,,N)up(k,,N))lable[hash.Hash_value(a[i]*(a[j]+a[k]))]++;
}
void init(){
N=read();
up(i,,N)a[i]=read();
}
void slove(){
up(i,,N),N),N)/*x_2*/
ans+=lable[hash.Hash_value(a[i]+a[j]*a[k])];
}
void output(){
cout<<ans<<endl;
}
}
int main(){
//freopen("input.in","r",stdin);
using namespace solution;
init();
pret();
slove();
output();
//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
;
}
SPOJ:ABCDEF的更多相关文章
- Meet in the middle算法总结 (附模板及SPOJ ABCDEF、BZOJ4800、POJ 1186、BZOJ 2679 题解)
目录 Meet in the Middle 总结 1.算法模型 1.1 Meet in the Middle算法的适用范围 1.2Meet in the Middle的基本思想 1.3Meet in ...
- SPOJ ABCDEF题解
题面 源 OJ 未 AC(卡 \(map\) ,不想写 \(hash\) ). 看到 \(n \leq 100\) ,显然 \(O(n^6)\) 会挂掉,所以要优化. 考虑到原式可化为 \(a \ti ...
- OI卷题记录
2021.8.2 LG3386 匈牙利算法 二分图 LG1377 笛卡尔树 题解 2021.8.3 LG2962 \(\text{Meet in middle}\) LG3389 高斯消元 高斯-约旦 ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
随机推荐
- Java程序-进程中的"进程"
进程 我们知道程序在磁盘上的时候是静态的,当他被加载到内存的时候,就变成了一个动态的,称为进程,如下图是程序被加载到内存后,在内存中的分布情况如下 此图来自http://blog.csdn. ...
- exgcd,求乘法逆元
procedure exgcd(a,b:int64); var t:longint; begin then begin x:=;y:=; exit; end else exgcd(b,a mod b) ...
- <string> 与<string.h>、<cstring>的区别
<string.h> <string.h>是C版本的头文件,包含比如strcpy.strcat之类的字符串处理函数. <cstring> 在C++标准化(1998年 ...
- SharePoint 2013 安装图解
转自: http://www.cnblogs.com/jianyus/archive/2013/02/01/2889653.html 介绍:文章就是SharePoint2013安装过程的图解,包括步骤 ...
- 导入dmp文件时的注意事项
来源于:http://bbs.csdn.net/topics/350167817 --1表空间 CREATE TABLESPACE newjw DATAFILE 'E:\oracle_data\new ...
- Spring + Spring MVC+Hibernate框架整合详细配置
来源于:http://www.jianshu.com/p/8e2f92d0838c 具体配置参数: Spring: spring-framework-4.2.2Hibernate: hibernate ...
- freemarker 分页取值
<#if pagination??&&pagination.list??> <#list pagination.list as video> <td al ...
- find常见用法
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...
- iPad开发--UIPopoverController简单使用iOS7之前和iOS7之后的使用方法
一.iOS7之前的Popover的使用 对Popover进行懒加载处理 内容控制器中设置Popover弹出后的尺寸 设置显示的位置,两种情况.1 -- 给BarButtonItem设置Popover的 ...
- Notes on 'Selective Search For Object Recognition'
UijlingsIJCV2013, Selective Search For Object Recognition code 算法思想 利用分割算法将图片细分成很多region, 或超像素. 在这个基 ...