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 的房子 ...
随机推荐
- 移动对meta的定义
以下是meta每个属性详解 尤其要注意的是content里多个属性的设置一定要用分号+空格来隔开,如果不规范将不会起作用. 一.<meta http-equiv="Content-Ty ...
- MOSS 2010:Visual Studio 2010开发体验(14)——列表开发之事件接收器
转:http://boke.25k5.com/kan141919.html 通过前面几篇,我们已经完成了内容类型,列表定义,列表实例g 8h"@的开发.本篇继续讲解列表中的一个重要环节- ...
- 如何合并IP网段
1. 安装IPy pip3 install IPy 2. 写脚本: yuyue@workplace:~ $ cat combine_ip.pyfrom IPy import IPSet, IPimpo ...
- hdu 3038 How Many Answers Are Wrong(种类并查集)2009 Multi-University Training Contest 13
了解了种类并查集,同时还知道了一个小技巧,这道题就比较容易了. 其实这是我碰到的第一道种类并查集,实在不会,只好看着别人的代码写.最后半懂不懂的写完了.然后又和别人的代码进行比较,还是不懂,但还是交了 ...
- DevExpress控件使用小结 z
.TextEditor(barEditItem)取文本 string editValue = barEditItem1.EditValue.ToString(); //错误,返回null string ...
- 直线相交 POJ 1269
// 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...
- pyinstaller使用小结
安装pyinstaller pip install -U pyinstaller 生成控制台程序 pyinstaller ./example.py 在当前目录的dist文件夹内可以找到编译成功的程序 ...
- 《Java数据结构与算法》笔记-CH1
/** * 数据结构的特性 ************************************************************************************** ...
- workstack windows to openstack
https://www.mirantis.com/openstack-portal/express-openstack-portal/migrating-from-vmware-for-windows ...
- cloudera hbase集群简单思路
文章copy link:http://cloudera.iteye.com/blog/889468 链接所有者保留所有权! http://www.csdn.net/article/2013-05-10 ...