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. 【大数比较】NYOJ-73

    比大小 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 给你两个很大的数,你能不能判断出他们两个数的大小呢? 比如123456789123456789要大于-1234 ...

  2. site

    http://blog.csdn.net/zgmzyr/article/details/7657126

  3. tcprstat源码分析之tcp数据包分析

    tcprstat是percona用来监测mysql响应时间的.不过对于任何运行在TCP协议上的响应时间,都可以用.本文主要做源码分析,如何使用tcprstat请大家查看博文<tcprstat分析 ...

  4. 试验笔记 - Eclipse的.class反编译插件

    常用的反编译工具有: JAD Java Decompiler Download Mirror(?) http://varaneckas.com/jad/ JadClipse (较好) http://j ...

  5. ASP.NET QueryString乱码解决问题

    正常的情况下,现在asp.net的网站很多都直接使用UTF8来进行页面编码的,这与Javascript.缺省网站的编码是相同的,但是也有相当一部分采用GB2312. 对于GB2312的网站如果直接用j ...

  6. springmvc基础知识

    springmvc框架,类似于struts,主要用于MVC的控制层 spring的简单配置(非注解):  spring-mvc.xml文件(springMVC框架的基本文件) web.xml文件 ja ...

  7. 双网卡bond

           使用双网卡虚拟为一块网卡: 服务器版本: [root@kel ~]# lsb_release -a LSB Version: :core-3.1-amd64:core-3.1-ia32: ...

  8. 【和我一起学Python吧】Python3.0与2.X版本的区别

    做为一个前端开发的码农,却正在阅读最新版的<A byte of Python>.发现Python3.0在某些地方还是有些改变的.准备慢慢的体会,与老版本的<A byte of Pyt ...

  9. 写i2c_client驱动的两种方式

    http://www.cnblogs.com/simonshi/archive/2011/02/24/1963426.html

  10. MFC 解析xml文件

    CComVariant IXMLDOMElement http://blog.sina.com.cn/s/blog_69e905cd0100kp5i.html