Codeforces 658D Bear and Polynomials【数学】
题目链接:
http://codeforces.com/contest/658/problem/D
题意:
给定合法多项式,改变一项的系数,使得P(2)=0,问有多少种方法?
分析:
暴力求和然后依次试一试肯定不行啦~
仔细想想,多项式和为0,就是说存在某个2i,使得剩下的和等于x∗2i,(其中x 的绝对值小于等于k)。
那我们就从最小的开始看。把系数依次向后移。
如果系数ai为偶数,那么ai∗2i=(ai/2)∗2i+1,就令bi=0,否则bi=1,最终所有系数都移到了2n上。
如果某个bi为奇数的话,就是说不能完全转化成后面的数,无法用比他大的数表示他,那么后面的系数怎么变也抵消不了。所以我们只能看他自己和他前面的元素,通过改变这些元素的系数试图抵消它。
最后倒着算一遍,算出对于每个位置,可以抵消后面的数的系数,然后。。。减一下他自己。。。就可以了。。。。
然后注意一下倒着求和过程中res的绝对值大于INF的情况,直接break。
代码:
#include <cstdio>
const int maxn = 200005, INF = 1e18;
long long t[maxn],a[maxn], b[maxn];
int main (void)
{
int n, k;
long long res = 0;
scanf("%d%d",&n, &k);
for(int i = 0; i <= n; i++){
scanf("%I64d",&a[i]);
}
b[n] = a[n];
int flag;
for(int i = 0; i < n; i++){
int tmp = b[i] + a[i] ;
b[i + 1] += tmp / 2ll;
b[i] = tmp % 2ll;
}
for(int i = 0; i <= n; i++){
if(b[i]){flag = i; break;}//记录
}
int cnt = 0;
for(int i = n; i >= 0; i--){
res = res * 2ll + b[i];
if(res > INF || res < -INF )break;
if(i <= flag){
int ans = a[i] - res;
if(ans >= -k && ans <= k && (ans != 0 || i != n)){
cnt++;
}
}
}
printf("%d\n", cnt);
}
/*
5 5
0 -4 -2 -2 0 5
*/
智商压制,想的有点久。。。不过还是涨姿势!
Codeforces 658D Bear and Polynomials【数学】的更多相关文章
- codeforces 658D D. Bear and Polynomials(数学)
题目链接: D. Bear and Polynomials time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- CodeForces 639C Bear and Polynomials
Bear and Polynomials 题解: 如果改变一个其中的一个数,那么需要知道的是,前面的数都可以进到当前位来,如果过不来的话,那么就会因为前面有数导致无法变成0. 所以我们将前面的数不断向 ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) D. Bear and Polynomials
D. Bear and Polynomials 题目连接: http://www.codeforces.com/contest/658/problem/D Description Limak is a ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...
- Codeforces 791B Bear and Friendship Condition(DFS,有向图)
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...
随机推荐
- IOS访问webserver接口
接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet) 需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon, ...
- IOS状态栏
IOS状态栏是什么地方? 它是IOS设备屏幕顶部显示信号以及电池的区域.状态栏默认的高度是20像素,状态栏在软件开发中有何作用?联网应用中可在自动帮用户下载数据时使用,推荐在状态栏中予以显示.状态栏可 ...
- SQL Server时间类型datetime
SQL Server时间类型datetime 兼容ADO的COleDateTime. SQL datetime 日期和时间数据,可表示1753.1.1 至 9999.12.31的时间,精度为1/300 ...
- VTK教程系列:VTK基础及应用开发教程
由于OpenCV不能使用,只能使用VTK库的图像处理库,暂时还没有找到其他可以全面替代的库: CSDN东灵工作室:http://blog.csdn.net/www_doling_net/article ...
- 关于dzzoffice 破解版
最近看到很多人在搜索dzzoffice破解版,其实dzzoffie是一款全开源的产品,开放的功能是与演示站中一摸一样的,所以并不会有人破解这种全开源的系统.那么为什么会有人搜索这样的关键词呢? 可能大 ...
- contos7 使用zabbix监控物理磁盘状态实例
一.系统环境: 物理机:dell R640 操作系统:centos7 二.安装MegaCli 监控主要是通过MegaCli 软件获取到物理主机的read及硬盘相关状态信息.然后通过zabbix的自定义 ...
- Eaton Char-Lynn Motor : Performance Of Small Displacement Motors
The small-displacement supercharged motor replaces the large-displacement motor with the speed of li ...
- docker 离线安装
适用于: 1.内网安装docker 2.内网升级docker debian 8 sudo apt-get updatesudo apt-get install -d apt-transport-htt ...
- 倍增实现LCA
Today,we will talk about how to find The Least Common Ancestor. Now ,let us get into the business(正题 ...
- 微信小程序wx.request请求服务器json数据并渲染到页面
[原文出自]: https://blog.csdn.net/weixin_39927850/article/details/79766259 微信小程序的数据总不能写死吧,肯定是要结合数据库来做数据更 ...