http://codeforces.com/contest/776/problem/C

一开始做的时候,就发现是预处理前缀和,然后对于每一个前缀和,如果他能成为一个贡献,就是能和前面的某些段

组合成和为k^x的话,那么需要cur_per_sum - val = k^x,这样可以解出val是多少,去前面找有多少个数是val就行了。

然后开始的时候我是先把所有数字都预处理然后放入map的,这样的做法是不对的,变得十分麻烦,

可能前面的前缀和是0,然后后面的前缀和也是0,但是当前枚举的这一位不能和后面的组合,这样就会GG。

所以可以枚举cur的时候,把cur - 1的东西放入去先,这样就不会被后面的影响。

记得特判1和-1的情况,特别是-1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + ;
map<LL, int>mipos;
map<LL, int>num;
const LL uppos = 1e14;
const LL upnag = -1e14;
LL sum;
LL mypow(LL k, LL b) {
LL ans = ;
for (int i = ; i <= b; ++i) {
ans *= k;
}
return ans;
}
void work() {
int n;
LL k;
cin >> n >> k;
num[] = ;
LL ans = ;
for (int i = ; i <= n; ++i) {
int x;
cin >> x;
sum += x;
int sel = ;
for (int j = ; ; ++j) {
LL now = mypow(k, j);
if (now > uppos) break;
if (now < upnag) break;
ans += num[sum - now];
sel++;
if (k == ) break;
if (k == - && sel == ) break;
}
num[sum]++;
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return ;
}

C. Molly's Chemicals 暴力 + 统计技巧的更多相关文章

  1. C. Molly's Chemicals

    题目链接:http://codeforces.com/problemset/problem/776/C C. Molly's Chemicals time limit per test 2.5 sec ...

  2. 牛客小白月赛5-I-区间(差分求前缀和+一次暴力统计)

    题目描述 Apojacsleam喜欢数组. 他现在有一个n个元素的数组a,而他要对a[L]-a[R]进行M次操作: 操作一:将a[L]-a[R]内的元素都加上P 操作二:将a[L]-a[R]内的元素都 ...

  3. HDU 1496 Equations 等式(二分+暴力,技巧)

    题意:给出4个数字a,b,c,d,求出满足算式a*x1^2+b*x2^2+c*x3^2+d*x4^2=0的 (x1,x2,x3,x4) 的组合数.x的范围[-100,100],四个数字的范围 [-50 ...

  4. mysql数据统计技巧备忘录

    mysql 作为常用数据库,操作贼六是必须的,对于数字操作相关的东西,那是相当方便,本节就来拎几个统计案例出来供参考! order订单表,样例如下: CREATE TABLE `t_order` ( ...

  5. [MySQL]group by 与 if 的统计技巧

    group by查询旨在把某字段中相同的记录合并成一列,查询结果可受count(),sum()等统计函数影响 如下表 id totalclick validclick 1 3 1 2 3 1 3 5 ...

  6. sql count统计技巧

    select count(1) from table where columnname=value 写成 select count(case when columnname=value than 1 ...

  7. [MySQL]group by 与 having 结合函数 的统计技巧

    group by 与 having 允许字段使用函数,根据函数运行的结果group by分组或having设置选择条件; 同时group by 与 having 也允许使用字段别名 示例表a: id ...

  8. Codeforces 776C - Molly's Chemicals(思维+前缀和)

    题目大意:给出n个数(a1.....an),和一个数k,问有多少个区间的和等于k的幂 (1 ≤ n ≤ 10^5, 1 ≤ |k| ≤ 10, - 10^9 ≤ ai ≤ 10^9) 解题思路:首先, ...

  9. HDU 1017A Mathematical Curiosity (暴力统计特殊要求个数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1017 A Mathematical Curiosity Time Limit: 2000/1000 M ...

随机推荐

  1. Docker and Go: why did we decide to write Docker in Go?

    Docker and Go: why did we decide to write Docker in Go? | Hacker News https://news.ycombinator.com/i ...

  2. jQuery 怎么获取对象

    1.JQuery的核心的一些方法 each(callback) '就像循环 $("Element").length; ‘元素的个数,是个属性 $("Element&quo ...

  3. JSON和JavaScript对象

    var obj={width:100,height:200},这样的并不叫JSON,并且JSON只是一种数据格式,并不是具体的实例. 但很多人把这样的JS对象当成JSON,下面把这个问题讲清楚 一.J ...

  4. hdoj 1875 畅通project再续【最小生成树 kruskal &amp;&amp; prim】

    畅通project再续 Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其它的小岛时都要通过划小船来实现. ...

  5. MessageBox_ swt

    SWT有不同类型的对话框.有些对话框具有特殊的属性. MessageBox messageBox = new MessageBox(shell, SWT.OK|SWT.CANCEL); if (mes ...

  6. if return 和 if else

    最近看Node.js实战中,有一段代码是优化之前使用if else,优化之后是使用if return,我不知道if return是不是效率比if else高. 优化前: if(err){ handle ...

  7. RedisCluster集群原理

    主从复制,数据值每个服务器都存了. 针对redis集群的解决方案, 连接这个集群,不用在乎Master了 6台redis 1.why use Redis? 减轻数据库访问压力 2.持久化 RDB(间隔 ...

  8. codeforces 459 A. Pashmak and Garden 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...

  9. silverlight中 ComboBox绑定数据库,并获取当前选定值

    silverlight中 ComboBox绑定数据库,并获取当前选定值 在silverlight中 用combobox下拉菜单绑定数据库的方法和用DataGrid绑定数据库的方法类似. page.xa ...

  10. Android中android:visibility的3中属性的剖析

    在Android中控件或者布局的可见性android:visibility有3中情况,他们分别是: View.VISIBLE,View.UNVISIBLE,View.GONE View.VISIBLE ...