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. 转:Java NIO系列教程(四) Scatter/Gather

    Java NIO开始支持scatter/gather,scatter/gather用于描述从Channel(译者注:Channel在中文经常翻译为通道)中读取或者写入到Channel的操作.分散(sc ...

  2. Yacc 与 Lex 快速入门

    Yacc 与 Lex 快速入门 Lex 与 Yacc 介绍 Lex 和 Yacc 是 UNIX 两个非常重要的.功能强大的工具.事实上,如果你熟练掌握 Lex 和 Yacc 的话,它们的强大功能使创建 ...

  3. Linux常用命令 查看进程信息时 copy的-----温故而知新

    1.查进程    ps命令查找与进程相关的PID号:    ps a 显示现行终端机下的所有程序,包括其他用户的程序.    ps -A 显示所有程序.    ps c 列出程序时,显示每个程序真正的 ...

  4. Minimum Inversion Number

    Minimum Inversion Number Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  5. A+B Again(在某个数中找大于m的最小约数)

    A+B Again Accepted : 15   Submit : 243 Time Limit : 1000 MS   Memory Limit : 65536 KB  题目描述 上次趣味赛小明的 ...

  6. codeforces 258div2C Predict Outcome of the Game

    题目链接:http://codeforces.com/contest/451/problem/C 解题报告:三个球队之间一共有n场比赛,现在已经进行了k场,不知道每个球队的胜场是多少,如三个球队的胜场 ...

  7. Unity3d iOS基本优化和高级优化

    原地址:http://www.cocoachina.com/bbs/read.php?tid=70395&page=1 分享看见的2篇好文.简单翻译了一下并且放出原文 http://www.c ...

  8. Minimum Depth of Binary Tree

    二叉树的最小深度 采用递归的方式求左右结点的高度,注意判断一个结点是否是叶子结点(左右子树都不存大). int minDepth(TreeNode *root) { return minDepth(r ...

  9. sqlMapConfig.xml配置文件详解

    sqlMapConfig.xml配置文件详解: Xml代码 Xml代码  <? xml version="1.0" encoding="UTF-8" ?& ...

  10. 深度学习入门教程UFLDL学习实验笔记一:稀疏自编码器

    UFLDL即(unsupervised feature learning & deep learning).这是斯坦福网站上的一篇经典教程.顾名思义,你将在这篇这篇文章中学习到无监督特征学习和 ...