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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. const int maxn = 1e5 + ;
  21. map<LL, int>mipos;
  22. map<LL, int>num;
  23. const LL uppos = 1e14;
  24. const LL upnag = -1e14;
  25. LL sum;
  26. LL mypow(LL k, LL b) {
  27. LL ans = ;
  28. for (int i = ; i <= b; ++i) {
  29. ans *= k;
  30. }
  31. return ans;
  32. }
  33. void work() {
  34. int n;
  35. LL k;
  36. cin >> n >> k;
  37. num[] = ;
  38. LL ans = ;
  39. for (int i = ; i <= n; ++i) {
  40. int x;
  41. cin >> x;
  42. sum += x;
  43. int sel = ;
  44. for (int j = ; ; ++j) {
  45. LL now = mypow(k, j);
  46. if (now > uppos) break;
  47. if (now < upnag) break;
  48. ans += num[sum - now];
  49. sel++;
  50. if (k == ) break;
  51. if (k == - && sel == ) break;
  52. }
  53. num[sum]++;
  54. }
  55. cout << ans << endl;
  56. }
  57.  
  58. int main() {
  59. #ifdef local
  60. freopen("data.txt", "r", stdin);
  61. // freopen("data.txt", "w", stdout);
  62. #endif
  63. IOS;
  64. work();
  65. return ;
  66. }

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. safi 中placeholder不垂直居中

    用css hack将line-height 设置为1 例子: input{height: 32px; line-height: 32px; [;line-height: 1px;]};

  2. HDU3416 Marriage Match IV —— 最短路径 + 最大流

    题目链接:https://vjudge.net/problem/HDU-3416 Marriage Match IV Time Limit: 2000/1000 MS (Java/Others)    ...

  3. 计算机学院大学生程序设计竞赛(2015’12)Happy Value

    Happy Value Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. 通过mysqldumpslow来分析日志

    通过mysqldumpslow来分析日志. 将mysql加入到全局变量中!!! sudo vim /etc/profile # 添加Mysql export PATH=$PATH:/usr/local ...

  5. 书写优雅的shell脚本(五)- shell中(())双括号运算符

    在使用shell的逻辑运算符"[]"使用时候,必须保证运算符与算数之间有空格. 四则运算也只能借助:let,expr等命令完成. 今天讲的双括号"(())"结构 ...

  6. 并不对劲的bzoj5415:loj2718:uoj393:p4768:[NOI2018]归程

    题目大意 \(n\)(\(n\leq2*10^5\))个点,\(m\)(\(m\leq4*10^5\))条边的图,每条边有海拔\(a_i(a_i\leq10^9)\).长度\(l_i(l_i\leq1 ...

  7. css 选择器中的正则表达式

    正则表达式在任何语言中都有使用,只是使用的形式不一样而已 css也是一门语言,也有自己的正则表达式 正则表达式中的一些通用规则: 1 ^ 表示字符串开始位置匹配 2 $表示字符串结束为止匹配 3 *表 ...

  8. UVa 1642 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  9. python mixin到底是什么 django

    1.什么是Mixin 在面向对象编程中,Mixin是一种类,这种类包含了其他类要使用的方法,但不必充当其他类的父类.其他类是如何获取Mixin中的方法因语言的不同而不同.所以有时候Mixin被描述为' ...

  10. SCUT - 48 - 飞行员的配对方案 - 费用流

    https://scut.online/p/48 一道二分图匹配,跑费用流就可以过了(其实最大流都可以了). #include<bits/stdc++.h> #define MAXN_ 5 ...