C. Molly's Chemicals 暴力 + 统计技巧
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 暴力 + 统计技巧的更多相关文章
- C. Molly's Chemicals
题目链接:http://codeforces.com/problemset/problem/776/C C. Molly's Chemicals time limit per test 2.5 sec ...
- 牛客小白月赛5-I-区间(差分求前缀和+一次暴力统计)
题目描述 Apojacsleam喜欢数组. 他现在有一个n个元素的数组a,而他要对a[L]-a[R]进行M次操作: 操作一:将a[L]-a[R]内的元素都加上P 操作二:将a[L]-a[R]内的元素都 ...
- 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 ...
- mysql数据统计技巧备忘录
mysql 作为常用数据库,操作贼六是必须的,对于数字操作相关的东西,那是相当方便,本节就来拎几个统计案例出来供参考! order订单表,样例如下: CREATE TABLE `t_order` ( ...
- [MySQL]group by 与 if 的统计技巧
group by查询旨在把某字段中相同的记录合并成一列,查询结果可受count(),sum()等统计函数影响 如下表 id totalclick validclick 1 3 1 2 3 1 3 5 ...
- sql count统计技巧
select count(1) from table where columnname=value 写成 select count(case when columnname=value than 1 ...
- [MySQL]group by 与 having 结合函数 的统计技巧
group by 与 having 允许字段使用函数,根据函数运行的结果group by分组或having设置选择条件; 同时group by 与 having 也允许使用字段别名 示例表a: id ...
- Codeforces 776C - Molly's Chemicals(思维+前缀和)
题目大意:给出n个数(a1.....an),和一个数k,问有多少个区间的和等于k的幂 (1 ≤ n ≤ 10^5, 1 ≤ |k| ≤ 10, - 10^9 ≤ ai ≤ 10^9) 解题思路:首先, ...
- HDU 1017A Mathematical Curiosity (暴力统计特殊要求个数)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1017 A Mathematical Curiosity Time Limit: 2000/1000 M ...
随机推荐
- Mac中配置eclipse的php开发环境
1.mac中自带php和apache,不过版本不是最新的. 2.打开apache配置文件中php相关设置,并设置php的工程目录为你想要的目录 3.复制php.ini.default为php.ini, ...
- curl请求接口返回false,错误码60
我讲一下我遇到的这个问题,是因为最近服务器加了https导致的,网上找到了答案,加上这句 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 就可以正常返 ...
- 解决Javascript md5 和 Java md5 中文加密后不同问题
Javascript md5 和 Java md5 带中文字符加密结果不一致,可以通过编码进行转化. javascript可以使用encodeURLComponent将中文先转化一次再进行MD5加密. ...
- safair 的css hack
在css里面使用[;attribute:value;] css参考如下: .header-share li{float: right; margin-left: 20px; [;width: 50px ...
- tload
tload命令以图形化的方式输出当前系统的平均负载到指定的终端.假设不给予终端机编号,则会在执行tload指令的终端机显示负载情形. 语法 tload(选项)(参数) 选项 -s:指定闲时的刻度: - ...
- SpringMVC上传多文件
springMVC实现 多文件上传的方式有两种,一种是我们经常使用的以字节流的方式进行文件上传,另外一种是使用springMVC包装好的解析器进行上传.这两种方式对于实 现多文件上传效率上却有着很大的 ...
- 安装ubuntu gnome 16.04后的一些操作
好吧...其实安装了挺久了,记录一下以防忘记... 1.软件 chrome浏览器 唔..自己去官网下吧.. gnome tweak tool 不用多说,必备 sudo apt-get install ...
- VS2008 MFC截取整个屏幕并保存为jpg格式
void CMainFrame::OnSavejpg() { // TODO: 在此添加命令处理程序代码 HWND hwnd = this->GetSafeHwnd(); //得到窗口句柄 HD ...
- linux mplayer 播放yuv格式 (转载)
转自:http://blog.csdn.net/ly0303521/article/details/38713791 在mplayer中查看YUV格式的图片或视频,可使用如下命令: mplayer - ...
- Tomcat黑窗口改变Title
start cmd /K " && call startup.bat && pause && exit " 设置Title之后,再手 ...