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

题意

给你一个序列,任意一个数只要等于在它前面的任意三个数之和(可以相同)则称为good数

题解

有时候能用数组尽量用数组,set还是有祸害的

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************
int s[];
int main()
{
int ans=;
int a[];
int n=read();
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
for(int j=;j<i;j++)
{
if(s[a[i]-a[j]+])
{
ans++;
break;
}
}
for(int j=;j<i;j++)
{
s[a[i]+a[j]+]=;
}
s[a[i]+a[i]+]=;
}
cout<<ans<<endl;
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 100203G Good elements 暴力乱搞

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

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

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

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

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

  5. Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

    原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...

  6. Codeforces Gym 100513G G. FacePalm Accounting

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

  7. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  8. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  9. Codeforces Gym 100513I I. Sale in GameStore 暴力

    I. Sale in GameStore Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/p ...

随机推荐

  1. struts2基本配置

    struts.xml 放在src目录下 <?xml version="1.0" encoding="UTF-8"?> <struts> ...

  2. sprintf()函数的用法

    sprintf(g_strAppName, "%s",pLast+1); ----------------------------------------------------- ...

  3. php-jquery-json-3

    memcache redis缓存技术mysql中的int和text是有区别的, , 按字节长度来记忆jquery中的选择器中的空格是运算符, 所以不能多也不能少, 非常严格层次运算符: 空格 大于 等 ...

  4. html-php深入理解

    不再纠结div p span. 写html的时候, 在头脑中, 要等同于/实际上就相当于写一篇图文混排的word文档, 有主标题/子标题, 有正文段落等等. 要根据这些标签的本身的语义来使用! div ...

  5. angularjs中关于当前路由再次点击强制刷新

    angularjs中,有一个机制,就是当前路由再次点击的时候,不会再刷新页面,这实在是愁坏了包子,因为业务人员要求一定要刷新,于是我各种百度,然并卵....呜呜呜~~~~~ 于是乎,我就想到写指令了, ...

  6. cocos代码研究(1)sprite学习笔记

    各种方法创建Sprite和Animate //图片创建法 参数一:图片资源路径 参数二:Rect选区 auto sprite = Sprite::create(, )); addChild(sprit ...

  7. Unity3D如何制作透贴和使用透贴模型

    http://momowing.diandian.com/post/2012-10-25/40040842845 Unity3D如何制作透贴和使用透贴模型??解决办法!!! 问题: 同事通过3DMAX ...

  8. MFC 最大化 的时候控件 按比例变大

    在dlg类头文件中声明CPoint Old; 在BEGIN_MESSAGE_MAP()和END_MESSAGE_MAP()声明一个映射:ON_WM_SIZE() 这样以后就可以在M_SIZE事件的时候 ...

  9. c++字符串详解(转)

    之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够.字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是 ...

  10. C++模板常用使用方法介绍

    转载:http://developer.51cto.com/art/201002/182202.htm C++编程语言中的模板应用在一定程度上大大提高了程序开发的效率.我们在这篇文章中为大家详细讲解一 ...