Codeforces Gym 100203G G - Good elements 暴力
G - Good elements
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87954#problem/G
Description
You are given a sequence A consisting of N integers. We will call the i-th element good if it equals the sum of some three elements in positions strictly smaller than i (an element can be used more than once in the sum).
How many good elements does the sequence contain?
Input
The first line of input contains the positive integer N (1 ≤ N ≤ 5000), the length of the sequence A.
The second line of input contains N space-separated integers representing the sequence A ( - 105 ≤ Ai ≤ 105).
Output
The first and only line of output must contain the number of good elements in the sequence.
Sample Input
2
1 3
Sample Output
1
HINT
题意
给你n个数,问你有多少个good数
每个good数的定义是,这个数如果能被他前面的任意三个数的和构成的话,(可以重复用)就是good数
题解:
n^2预处理出来所有数的两两之间的和,然后再暴力n^2找是否存在这样的和
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int maxn = 5e3 + ;
const int limit = 1e5;
int p[maxn] , n , ans = , exist[limit * ]; int main(int argc,char *argv[])
{
scanf("%d",&n);
memset(exist,,sizeof(exist));
for(int i = ; i <= n ; ++ i) scanf("%d",p+i);
exist[p[]* + limit*] = ;
if (p[] * == p[]) ans ++;
exist[p[] + p[] + limit*] = ;
exist[p[] * + limit*] = ;
for(int i = ; i <= n ; ++ i)
{
for(int j = ; j < i ; ++ j)
{
int dis = p[i] - p[j];
if (exist[dis+limit*])
{
ans ++;
break;
}
}
for(int j = ; j < i ; ++ j)
exist[p[i]+p[j]+limit*] = ;
exist[p[i] * + limit*] = ;
}
printf("%d\n",ans);
return ;
}
Codeforces Gym 100203G G - Good elements 暴力的更多相关文章
- Codeforces Gym 100203G G - Good elements 标记暴力
G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100203G Good elements 暴力乱搞
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- Codeforces Gym 100513G G. FacePalm Accounting
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- Codeforces Gym 100342E Problem E. Minima 暴力
Problem E. MinimaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attac ...
- Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)
题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...
随机推荐
- Informatica 9.1常用查询
select a.mapping_name, a.mapping_id, a.subject_id, a.is_valid, b.pv_precision, c.pv_value, b.pv_defa ...
- PHP学习笔记--文件目录操作(文件上传实例)
文件操作是每个语言必须有的,不仅仅局限于PHP,这里我们就仅用PHP进行讲解 php的文件高级操作和文件上传实例我放在文章的最后部分.--以后我还会给大家写一个PHP类似于网盘操作的例子 注意:阅读此 ...
- 获取apk信息工具(android SDK的aapt工具)
aapt命令是android SDK 中的一个工具,功能强大,比如在windows平台获取apk包的信息. 使用该工具准备条件,也即获取aapt.exe文件的方式(2选1即可): 安装android ...
- BLOCK 死循环
__weak typeof(self) weakSelf = self; myObj.myBlock = ^{ __strong typeof(self) strongSelf = weak ...
- PHP 获取文件权限函数
/* * substr 返回字符串的子串 * base_convert 在任意进制之间转换数字 * fileperms 取得文件的权限 */ // 获取权限 function getChmod($fi ...
- log4net 动态设定日志文件名
参考文章: http://blog.csdn.net/haoxiaozigang1/article/details/16343303 通过这个篇文章的方法,只能修改文件的路径,文件名并没有修改 参考文 ...
- JavaScript中的*top、*left、*width、*Height详解
来源:http://www.ido321.com/911.html html代码 1: <body> 2: <div class="father" id=&quo ...
- 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇:简介及目录》(附上完整工程文件)
G-3D引擎2D射击类游戏制作教程 游戏类型: 打飞机游戏属于射击类游戏中的一种,可以划分为卷轴射击类游戏. 视觉表现类型为:2D 框架简介: Genesis-3D引擎不仅为开发者提供一个3D游戏制作 ...
- Activating Google Cloud Storage
先决条件 你需要下面的内容: 1.一个Google账户,比如来自Gmail.如果你没有,请在Google account signup site注册. 2.一个新的或已经存在的Google Devel ...
- Hadoop Hive概念学习系列之为什么Hive里,要用mysql?(四)
想说的是,hive只是个工具,包括它的数据分析,依赖于mapreduce,它的数据管理,依赖于外部系统. metastore_db,是在哪目录下运行,在哪里产生数据. 由此可见,你在哪路径下,执行hi ...