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 暴力的更多相关文章

  1. Codeforces Gym 100203G G - Good elements 标记暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  2. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  3. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  4. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  5. Codeforces Gym 100513G G. FacePalm Accounting

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  6. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  7. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  8. Codeforces Gym 100342E Problem E. Minima 暴力

    Problem E. MinimaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attac ...

  9. Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)

    题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...

随机推荐

  1. CoreData 基本操作方法封装

    转:http://blog.csdn.net/marujunyy/article/details/18500523 为了方便使用CoreData 封装了几个扩展类,使用方法和类文件如下: //首先需要 ...

  2. hdu 2594-Simpsons’ Hidden Talents(KMP)

    题意: 给你两个串a,b,求既是a的前缀又是b的后缀的最长子串的长度. 分析: 很自然的想到把两个串连接起来,根据KMP的性质求即可 #include <map> #include < ...

  3. HDU 4035Maze(树状+概率dp,绝对经典)

    题意: 给你n个节点的树,从1节点开始走,到每个节点都有三种情况,被杀死回到1节点,找到隐藏的出口出去,沿着当前节点相邻的边走到下一个节点,给出每个节点三种情况发生的概率分别为ki,ei,1-ki-e ...

  4. node.js study: cluster

    从v0.6.x开始,Node.js提供了多进程模块cluster,允许创建一组进程来共享同一个socket,并且分担负载压力.官方文档是这样说的:A single instance of Node.j ...

  5. cadence异型孔

    1:画route path的边框,画在board geometry的ncroute_path层上,可以用zcopy (暂时没用过)      没有的话可能:WARNING: No route path ...

  6. CSS 3的display:盒类型详解

    在CSS中,使用display属性来定义盒的类型.总体来说,盒类型分为两类:inline和block.如div默认是block,span默认是Inline.可以通过display修改默认的表现方式. ...

  7. MVC和WebForm的优缺点对比

    1 WebForm优点 1)支持事件模型开发,得益于丰富的服务端组件,WebForm开发可以迅速的搭建Web应用 2)使用方便,入门容易 3)控件丰富的WebForm 2 WebForm缺点  1)封 ...

  8. android判断当前网络状态及跳转到设置界面

    今天,想做这个跳转到网络设置界面, 刚开始用 intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); 不料老是出现settings.Wirele ...

  9. matlab中图像处理常见用法

    一. 读写图像文件 1. imread imread函数用于读入各种图像文件,如:a=imread('e:/w01.tif') 注:计算机E盘上要有w01相应的.tif文件. 2. imwrite i ...

  10. openstack分布式安装

    一. keystone安装笔记 初次接触openstack,在尝试过单机部署以后不是很满意,就开始着手分布式部署,主要是按照openstack官网上的安装教程来的,本人安装的是目前最新的 I 版. 以 ...