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 ...
随机推荐
- ubuntu快速清理磁盘垃圾
.快速清理磁盘垃圾 磁盘空间又不够用了?尝试在终端窗口中输入sudo apt-get autoremove然后输入sudo apt-get clean,前一个命令会卸载系统中所有未被使用的依赖关系,后 ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- UINavigation拖动翻页
#import <UIKit/UIKit.h> #import "ViewController.h" //window窗口 #define WINDOW [[UIApp ...
- Android中多个调用Activity的问题
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" ...
- iPhone取消软件更新上边的1
去除设置的更新+1小红点提示主要分为越狱和非越狱设备两种方法. 越狱状态下方法: 首先将你的设备进行越狱: 越狱后安装ifile(这个自行搜索安装): 用ifile打开/System/Library/ ...
- Java--读写文件综合
package javatest; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream ...
- php增加对mysqli的支持
php增加对mysqli的支持 我在fedora下使用yum安装的php和mysql,但是发现php不支持myslqi,只能编译一个mysqli的扩展给php用了. 方法如下: 1.下载php 2 ...
- KDD-CUP Proposal
From 鞠源 已有 1303 次阅读 2012-11-25 21:09 |系统分类:科研笔记|关键词:会议 领域 justify 知识 KDDCUP - Competition is a stron ...
- try---catch异常处理
try { sc.Send(msg); return; } catch (Exception ex) { //AlertInfo("发送失败," + ex); return ; }
- JS 保留小数点后面2位小数
1. 最笨的办法....... [我就怎么干的.........] function get(){ var s = 22.127456 + ""; var str = ...