很好的一道思维题目(有坑点的)
来源:互联网 发布:数学作图软件 编辑:程序博客网 时间:2024/06/05 23:56
"47 is the quintessential random number," states the 47 society. And there might be a grain of truth in that.
For example, the first ten digits of the Euler's constant are:
2 7 1 8 2 8 1 8 2 8
And what's their sum? Of course, it is 47.
You are given a sequence S of integers we saw somewhere in the nature. Your task will be to compute how strongly does this sequence support the above claims.
We will call a continuous subsequence of S interesting if the sum of its terms is equal to 47.
E.g., consider the sequence S = (24, 17, 23, 24, 5, 47). Here we have two interesting continuous subsequences: the sequence (23, 24) and the sequence (47).
Given a sequence S, find the count of its interesting subsequences.
InputThe first line of the input file contains an integer T(T <= 10) specifying the number of test cases. Each test case is preceded by a blank line.
The first line of each test case contains the length of a sequence N(N <= 500000). The second line contains N space-separated integers – the elements of the sequence. Sum of any continuous subsequences will fit in 32 bit signed integers.
OutputFor each test case output a single line containing a single integer – the count of interesting subsequences of the given sentence.
Sample Input2 7 1 8 2 8 1 8 2 8 4 5 9
2 47 10047 47 1047 47 47
4ac代码:
#include<bits/stdc++.h>using namespace std;map<long long ,int >w;int main(){ int t; scanf("%d",&t); while(t--) { int n; w.clear(); scanf("%d",&n); long long sum=0,ans=0; w[sum]=1; for(int i=0; i<n; i++) { long long q; scanf("%lld",&q); sum+=q; w[sum]++; ans+= w[sum-47]; } printf("%lld\n",ans); }}这个题比较坑人的一点就是自然数是包括0的。
- 很好的一道思维题目(有坑点的)
- hdu1158(很好的一道dp思维练习)
- stl-map的一道很好的题目
- poj2513 很好的一道题目 并查集+字典树
- poj 3414 Pots(认为是一道很好的bfs题目)
- POJ 3057 Evacuation(一道很好可以加强对二分图理解的题目)
- hdu 1689 BFS+剪枝 求最小奇数环 很好很好的一道题目
- 很好的一道树状数组
- 很好的一道面试题
- 一道有趣的题目
- 一道用递规做的题目
- 经典的一道题目.
- 笔试的一道题目
- 一道题目的解答
- 一道小学的题目
- 一道猥琐的题目
- 爱因斯坦的一道题目
- 一道有趣的题目
- Hbase学习8_ 启动hbase 报错 Address already in use 的解决办法
- Linux下GIPO的操作
- Android随笔之——PackageManager详解
- 继承
- Codeforces 219C Color Stripe 贪心
- 很好的一道思维题目(有坑点的)
- [Maven] Missing artifact (解决办法),eclipse错误artifact丢失
- 你所不知的 CSS ::before 和 ::after 伪元素用法
- Python - 下载视频网站的视频
- iOS 静默推送实现(推送背景为个推)
- KVM学习:基础功能
- Spring Web MVC
- windows操作工具或技巧集合
- linux中pip安装步骤与使用详解