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还是有祸害的

代码:

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <queue>
  10. #include <typeinfo>
  11. #include <map>
  12. #include <stack>
  13. typedef long long ll;
  14. using namespace std;
  15. inline ll read()
  16. {
  17. ll x=,f=;
  18. char ch=getchar();
  19. while(ch<''||ch>'')
  20. {
  21. if(ch=='-')f=-;
  22. ch=getchar();
  23. }
  24. while(ch>=''&&ch<='')
  25. {
  26. x=x*+ch-'';
  27. ch=getchar();
  28. }
  29. return x*f;
  30. }
  31. //***************************
  32. int s[];
  33. int main()
  34. {
  35. int ans=;
  36. int a[];
  37. int n=read();
  38. for(int i=;i<=n;i++)
  39. {
  40. scanf("%d",&a[i]);
  41. for(int j=;j<i;j++)
  42. {
  43. if(s[a[i]-a[j]+])
  44. {
  45. ans++;
  46. break;
  47. }
  48. }
  49. for(int j=;j<i;j++)
  50. {
  51. s[a[i]+a[j]+]=;
  52. }
  53. s[a[i]+a[i]+]=;
  54. }
  55. cout<<ans<<endl;
  56. return ;
  57. }

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. ubuntu快速清理磁盘垃圾

    .快速清理磁盘垃圾 磁盘空间又不够用了?尝试在终端窗口中输入sudo apt-get autoremove然后输入sudo apt-get clean,前一个命令会卸载系统中所有未被使用的依赖关系,后 ...

  2. Y2K Accounting Bug(贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 54 ...

  3. UINavigation拖动翻页

    #import <UIKit/UIKit.h> #import "ViewController.h" //window窗口 #define WINDOW [[UIApp ...

  4. Android中多个调用Activity的问题

    <application android:allowBackup="true" android:icon="@drawable/ic_launcher" ...

  5. iPhone取消软件更新上边的1

    去除设置的更新+1小红点提示主要分为越狱和非越狱设备两种方法. 越狱状态下方法: 首先将你的设备进行越狱: 越狱后安装ifile(这个自行搜索安装): 用ifile打开/System/Library/ ...

  6. Java--读写文件综合

    package javatest; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream ...

  7. php增加对mysqli的支持

    php增加对mysqli的支持   我在fedora下使用yum安装的php和mysql,但是发现php不支持myslqi,只能编译一个mysqli的扩展给php用了. 方法如下: 1.下载php 2 ...

  8. KDD-CUP Proposal

    From 鞠源 已有 1303 次阅读 2012-11-25 21:09 |系统分类:科研笔记|关键词:会议 领域 justify 知识 KDDCUP - Competition is a stron ...

  9. try---catch异常处理

    try { sc.Send(msg); return; } catch (Exception ex) { //AlertInfo("发送失败," + ex); return ; }

  10. JS 保留小数点后面2位小数

    1. 最笨的办法....... [我就怎么干的.........] function get(){    var s = 22.127456 + "";    var str = ...