Codeforces Gym 100203G G - Good elements 标记暴力
2015-08-16 00:15
537 查看
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还是有祸害的
代码:
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=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //*************************** int s[5000000]; int main() { int ans=0; int a[50004]; int n=read(); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); for(int j=1;j<i;j++) { if(s[a[i]-a[j]+500000]) { ans++; break; } } for(int j=1;j<i;j++) { s[a[i]+a[j]+500000]=1; } s[a[i]+a[i]+500000]=1; } cout<<ans<<endl; return 0; }
相关文章推荐
- UVa 11292 - Dragon of Loowater
- Codeforces Gym 100203G G - Good elements 暴力
- Codeforces Gym 100203G Good elements 暴力乱搞
- MetaStudio和DataScraper链接失败及登陆问题的解决(GooSeeker产品)
- STL algorithm中的swap 函数使用
- Django基础学习<2>
- hdu 3635 Dragon Balls
- HDU 5289 Assignment (二分+RMQ)
- go read text file into string array
- Django基础学习<1>
- HDU 2255 奔小康赚大钱 POJ 2195 Going Home 最大权完美匹配 KM算法
- Go 函数
- django-rest-framework指南(1):序列化
- Google编码规范
- Go语言入门
- Heagon的程序流程(二)
- Django(上)
- [转] Google工程师教你编写垃圾回收器
- POJ 2262 Goldbach's Conjecture(素数筛选法)
- uva 12300 - Smallest Regular Polygon(几何)