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
题意
给你一个序列,任意一个数只要等于在它前面的任意三个数之和(可以相同)则称为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 标记暴力的更多相关文章
- 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 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 100286J Javanese Cryptoanalysis 傻逼暴力
原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...
- Codeforces Gym 100513G G. FacePalm Accounting
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
- 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 ...
随机推荐
- 如果jsp提交到action为空指针的话
很严重的一点:表单<form>有没有添加一个method="post",如果表单的这个没有写,肯定是空指针, 哎,被这个坑爹的代码,查了好久,特此记录下
- http 超文本传输协议
超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的是为了提供一种发布和接 ...
- Java中的final修饰符
1.什么时候可以选择final修饰符 如果想让一个类不被其他类继承,不允许在有子类,这时候就要考虑用到final来修饰. 2.用final修饰的类 首先大家要明白,用final修饰的类是不能被继承的, ...
- 破解LR时,解决loadrunner 破解错误:license security violation.Operation is not allowed
一.由于在压力测试执行中,出现一个-10803的错误 ,为解决这个错误,重新设置的环境变量,在次执行错误,这个问题解决了,但另外一个问题出来了,LR,打开脚本编辑器老提示找不到TEMP目录,当时没有想 ...
- Android 中this、 getApplicationContext()、getApplication()之间的区别
this:代表当前,在Activity当中就是代表当前的Activity,换句话说就是Activity.this在Activity当中可以缩写为this. getApplicationContext( ...
- [Effective JavaScript 笔记] 第6条:了解分号插入的局限
分号可以省略 js可以在语句结束不强制加分号.(建议还是添加,不添加分号往往会出现不易发现的BUG) function Point(x,y){ this.x=x||0; this.y=y||0; } ...
- ubuntu12.04 Daemon的简单实现
使用命令 start-stop-daemon 官方文档:http://manpages.ubuntu.com/manpages/lucid/en/man8/start-stop-daemon.8.ht ...
- python 下载文件 & 防盗链
偶然下载一种类型的资源,发现好多翻页,右键另存什么的,不胜其烦. 决定用python写几句代码搞定.核心代码如下: from urllib import urlretrieve from urllib ...
- apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) 今天用apache 自带的ab工具测试,当并发量达到1000多的时 ...
- dom 中事件
阻止表单提交: function aa(){ return false; } function bb(event){ event.preventDefault(); } 事件不再派发: <!DO ...