JZOJ 3508. 【NOIP2013模拟11.5B组】好元素
3508. 【NOIP2013模拟11.5B组】好元素(good)
(File IO): input:good.in output:good.out
Description
Input
第二行包含N个整数,表示数列An。
Output
Sample Input
输入1:
2
1 3
输入2:
6
1 2 3 5 7 10
输入3:
3
-1 2 0
Sample Output
输出1:
1
输出2:
4
输出3:
1
Data Constraint
对于40%的数据 1<=N<=500 -10^5<=Ai<=10^5
对于70%的数据 1<=N<=5000 -10^6<=Ai<=10^6
对于100%的数据 1<=N<=5000 -10^9<=Ai<=10^9
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define N 5007
#define mo 14150547
#define z 2000000000
#define LL long long
using namespace std;
LL n, a[N], h[mo + ];
int ans;
bool f; LL hash(LL x)
{
LL p = x % mo;
while (h[p] != && h[p] != x - z && p <= mo) p = (p + ) % mo;
return p;
} void work()
{
for (int i = ; i <= n; i++)
{
for (int j = ; j < i; j++)
if (h[hash(a[i] - a[j] + z)] == a[i] - a[j] && a[i] - a[j] != )
{
ans++;
break;
}
else if (a[i] - a[j] == )
{
if (f)
{
ans++;
break;
}
}
for (int j = ; j <= i; j++)
{
LL p = (a[i] + a[j] + z) % mo;
while (h[p] != a[i] + a[j] && h[p] != && p <= mo) p = (p + ) % mo;
if (a[i] + a[j] != ) h[p] = a[i] + a[j];
else f = true;
}
}
} int main()
{
freopen("good.in", "r", stdin);
freopen("good.out", "w", stdout);
scanf("%lld", &n);
for (int i = ; i <= n; i++)
scanf("%lld", &a[i]);
work();
cout << ans;
}
JZOJ 3508. 【NOIP2013模拟11.5B组】好元素的更多相关文章
- JZOJ 3509. 【NOIP2013模拟11.5B组】倒霉的小C
3509. [NOIP2013模拟11.5B组]倒霉的小C(beats) (File IO): input:beats.in output:beats.out Time Limits: 1000 ms ...
- JZOJ 3518. 【NOIP2013模拟11.6A组】进化序列(evolve)
3518. [NOIP2013模拟11.6A组]进化序列(evolve) (File IO): input:evolve.in output:evolve.out Time Limits: 1000 ...
- JZOJ 3505. 【NOIP2013模拟11.4A组】积木(brick)
3505. [NOIP2013模拟11.4A组]积木(brick) (File IO): input:brick.in output:brick.out Time Limits: 1000 ms Me ...
- JZOJ 3526. 【NOIP2013模拟11.7A组】不等式(solve)
3526. [NOIP2013模拟11.7A组]不等式(solve) (File IO): input:solve.in output:solve.out Time Limits: 1000 ms M ...
- [jzoj]3506.【NOIP2013模拟11.4A组】善良的精灵(fairy)(深度优先生成树)
Link https://jzoj.net/senior/#main/show/3506 Description 从前有一个善良的精灵. 一天,一个年轻人B找到她并请他预言他的未来.这个精灵透过他的水 ...
- JZOJ【NOIP2013模拟联考14】隐藏指令
JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...
- [jzoj 5343] [NOIP2017模拟9.3A组] 健美猫 解题报告 (差分)
题目链接: http://172.16.0.132/senior/#main/show/5343 题目: 题解: 记旋转i次之后的答案为$ans_i$,分别考虑每个元素对ans数组的贡献 若$s_i& ...
- [JZOJ 4307] [NOIP2015模拟11.3晚] 喝喝喝 解题报告
题目链接: http://172.16.0.132/senior/#main/show/4307 题目: 解题报告: 题目询问我们没出现坏对的连续区间个数 我们考虑从左到有枚举右端点$r$,判断$a[ ...
- JZOJ 3487. 【NOIP2013模拟联考11】剑与魔法(dragons)
3487. [NOIP2013模拟联考11]剑与魔法(dragons) (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB De ...
随机推荐
- new 和 delete 用法
1. 这两个其实是 C++ 语言标准库的库函数,原型分别如下: void *operator new(size_t); //allocate an object void *operator dele ...
- 牛客网Java刷题知识点之基本数据类型参数传递和引用数据类型参数传递图解
不多说,直接上干货! //基本数据类型参数传递 class Demo { public static void main(String[] args) { ; show(x); System.out. ...
- 分布式锁-session-事务相关
1. 分布式锁--zookeeper 1). client调用create()方法创建"/root/lock_"节点,注意节点类型是EPHEMERAL_SEQUENTIAL. 2) ...
- webpack.config.js====引入Jquery库文件
1. 安装 cnpm install --save jquery expose-loader 2. 在webpack.config.js中配置 Jquery库是使用的webpack的一个插件Provi ...
- Web框架的应用
从今天开始,我们将要学习有关Web框架的一些内容,在学习之前先来学习一下http协议,即基于http是如何通信的. http 概要:http是基于tcp/ip通信协议来传输数据的. 优点: 1.简单快 ...
- 提高jquery加载速率(有cdn就加载,没有就加载本地)
<!-- Adds google cdn reference --> <script src="https://cdn.bootcss.com/jquery/3.2.1/j ...
- 【extjs6学习笔记】1.13 初始: 模型
Ext JS包括数据包Ext.data包括处理从服务器保存和检索数据的类. 以下是Ext JS 6数据包中的重要类: Model (Ext.data.Model) Store (Ext.data.St ...
- linux 下源码编译环境配置
yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel \ fontconfig fo ...
- python super用法
普通继承 class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print 'Parent' de ...
- HDU 2955 Robberies抢劫案(01背包,变形)
题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个 ...