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值的和 ...
 
随机推荐
- 通向高可扩展性之路(WhatsApp篇)---- 脸书花了190亿买来的WhatsApp的架构
			
原文链接:http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-bill ...
 - 柯尔莫可洛夫-斯米洛夫检验(Kolmogorov–Smirnov test,K-S test)
			
柯尔莫哥洛夫-斯米尔诺夫检验(Колмогоров-Смирнов检验)基于累计分布函数,用以检验两个经验分布是否不同或一个经验分布与另一个理想分布是否不同. 在进行cumulative probab ...
 - Bootstrap中glyphicons-halflings-regular.woff字体报404错notfound
			
今天查看网站的源代码,发现有个glyphicons-halflings-regular.woff文件没有找到,因为我的网站使用了bootstrap的Glyphicons 字体图标,因此需要加载Glyp ...
 - offsetleft、offsetTop、offsetParent的兼容性问题
			
先来看看offsetParent返回的是什么值 ele.offsetParent返回的是ele元素最近的并且是定位过(relative,absolute)的父元素,如果没有父元素或者是父元素中没有一个 ...
 - spring配置属性的两种方式
			
spring配置属性有两种方式,第一种方式通过context命名空间中的property-placeholder标签 <context:property-placeholder location ...
 - java中的重绘
			
void java.awt.Container.validate()Validates this container and all of its subcomponents.这个函数更新容器及其全部 ...
 - 【瞎想】TDD与汉字;FDD与英语字母
			
我觉得TDD与汉字;FDD与英语字母他们之间有相似性. FDD的上行和下行用频率的不同来区分,TDD的上行和下行用相同的频率然后在同一时刻相差半个波长(对称频率).如果用维度数描述,FDD是1维的话, ...
 - Sharepoint 杂记
			
在Sharepoint中复制Settle.html,粘贴后改名为km.html,修改km.html会自动更新km.master,修改好模板后需要在站点发布. 添加List添加WebPart,继承KmW ...
 - git创建仓库
			
创建仓库 git init: Git 使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令. ...
 - 链栈的C语言实现
			
/* 功能:栈的链表实现 Author:lxm Date: 20160511 */ #include <stdio.h> #include <stdlib.h> #define ...