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 + 50; const int limit = 1e5; int p[maxn] , n , ans = 0 , exist[limit * 6];int main(int argc,char *argv[]) {scanf("%d",&n);memset(exist,0,sizeof(exist));for(int i = 1 ; i <= n ; ++ i) scanf("%d",p+i);exist[p[1]*2 + limit*2] = 1;if (p[1] * 3 == p[2]) ans ++;exist[p[1] + p[2] + limit*2] = 1;exist[p[2] * 2 + limit*2] = 1;for(int i = 3 ; i <= n ; ++ i){for(int j = 1 ; j < i ; ++ j){int dis = p[i] - p[j];if (exist[dis+limit*2]){ans ++;break;}}for(int j = 1 ; j < i ; ++ j)exist[p[i]+p[j]+limit*2] = 1;exist[p[i] * 2 + limit*2] = 1;}printf("%d\n",ans);return 0; }
Codeforces Gym 100203G G - Good elements 暴力相关推荐
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 101473D Folding Machine (暴力搜索)
题目连接: http://codeforces.com/gym/101473/attachments 原先以为按照这个复杂度还要剪一下支,没想到暴力dfs完全可以通过. 代码: #include &l ...
- Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)
题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, -, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...
- Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks
Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...
- Educational Codeforces Round 25 G. Tree Queries
题目链接:Educational Codeforces Round 25 G. Tree Queries 题意: 给你一棵树,一开始所有的点全是黑色,有两种操作. 1 x 将x这个点变为黑色,保证第一 ...
- Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)
Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...
- [Codeforces Gym 101651/100725B] Banal Tickets
Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...
- Codeforces gym 100685 A. Ariel 暴力
A. Ariel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Des ...
- Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力
原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...
最新文章
- 【资源汇总分享】Android开发资源汇总之一
- Frida-跨平台注入工具基础篇
- 一文弄懂神经网络中的反向传播法——BackPropagation【转】
- [BZOJ] 2064: 分裂
- ByteBufferMessageSet分析
- java 远程监控文件系统_Java 文件系统监控(WatchService)
- linux内核sysfs详解【转】
- 普通索引和唯一索引,应该怎么选择?
- 最佳Excel导入实践(一)
- python 异常类型
- java 1.6 jre 下载_jre1.6下载-Java环境 官方版 - 安下载
- Win11到底意味着什么
- 处理C盘容量不足问题(以AppData为例)
- 推荐几款优质 Mac 软件下载网站 - 从此告别软件荒
- 王者android与ios互通,王者荣耀ios和安卓数据互通吗?数据互通时代即将来临
- 炒菜机器人“精确”破题中餐标准化
- URL中“#” “?” “”号的作用
- Java核心技术:集合——映射
- Oracle视图列名可以小写吗,oracle表列名大小写
- 如何快速的获取微博内容?