codeforces 658D D. Bear and Polynomials(数学)
题目链接:
2 seconds
256 megabytes
standard input
standard output
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:
Let a0, a1, ..., an denote the coefficients, so . Then, a polynomial P(x) is valid if all the following conditions are satisfied:
- ai is integer for every i;
- |ai| ≤ k for every i;
- an ≠ 0.
Limak has recently got a valid polynomial P with coefficients a0, a1, a2, ..., an. He noticed that P(2) ≠ 0 and he wants to change it. He is going to change one coefficient to get a valid polynomial Q of degree n that Q(2) = 0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
The first line contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 109) — the degree of the polynomial and the limit for absolute values of coefficients.
The second line contains n + 1 integers a0, a1, ..., an (|ai| ≤ k, an ≠ 0) — describing a valid polynomial . It's guaranteed that P(2) ≠ 0.
Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0.
3 1000000000
10 -9 -3 5
3
3 12
10 -9 -3 5
2
2 20
14 -7 19
0
In the first sample, we are given a polynomial P(x) = 10 - 9x - 3x2 + 5x3.
Limak can change one coefficient in three ways:
- He can set a0 = - 10. Then he would get Q(x) = - 10 - 9x - 3x2 + 5x3 and indeed Q(2) = - 10 - 18 - 12 + 40 = 0.
- Or he can set a2 = - 8. Then Q(x) = 10 - 9x - 8x2 + 5x3 and indeed Q(2) = 10 - 18 - 32 + 40 = 0.
- Or he can set a1 = - 19. Then Q(x) = 10 - 19x - 3x2 + 5x3 and indeed Q(2) = 10 - 38 - 12 + 40 = 0.
In the second sample, we are given the same polynomial. This time though, k is equal to 12 instead of 109. Two first of ways listed above are still valid but in the third way we would get |a1| > k what is not allowed. Thus, the answer is 2 this time.
题意:
问能不能改变一个系数使Q(2)=0;
思路:
像二进制那样都变成0,-1,+1,都转移到n位上;再从高位到低位计算;
AC代码:
/*
2014300227 658D - 26 GNU C++11 Accepted 576 ms 5308 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
long long a[N],b[N+];
int n,l=,k;
int main()
{ scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
for(int i=;i<n;i++)
{
a[i+]+=a[i]/;
a[i]=a[i]%;
}
for(int i=;i<=n;i++)
{
if(a[i])
{
l=i;
break;
}
}
int answ=;
long long sum=;
for(int i=n;i>=;i--)
{
sum=sum*+a[i];
if(abs(sum)>1e10)break;
if(i<=l)
{
long long x=abs(sum-b[i]);
if(x==&&i==n)continue;
if(x<=k)answ++;
}
}
cout<<answ<<"\n";
return ;
}
codeforces 658D D. Bear and Polynomials(数学)的更多相关文章
- 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 658D Bear and Polynomials【数学】
题目链接: http://codeforces.com/contest/658/problem/D 题意: 给定合法多项式,改变一项的系数,使得P(2)=0,问有多少种方法? 分析: 暴力求和然后依次 ...
- Codeforces 902D/901B - GCD of Polynomials
传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如 ...
- 【32.89%】【codeforces 574D】Bear and Blocks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 735C:Tennis Championship(数学+贪心)
http://codeforces.com/problemset/problem/735/C 题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局.问这n个人里面冠军最多能赢多少场, ...
- codeforces 680C C. Bear and Prime 100(数论)
题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces 680B B. Bear and Finding Criminals(水题)
题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...
- codeforces 680A A. Bear and Five Cards(水题)
题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...
随机推荐
- css:颜色名和十六进制数值
http://www.w3school.com.cn/cssref/css_colornames.asp
- 3、C++新的关键字
C++ 添加了一些全新的关键字. 1.new new 来进行动态内存的分配,而delect 则是进行内存的释放, 申请的方式: 变量申请: int *p = new int; // 申 ...
- http url转义字符,特殊字符
空格 - %20 " - %22 # - %23 % - %25 & - %26 ( - %28 ) - %29 + - %2B , - %2C / - %2F : - %3A ; ...
- jQuery--基础(查询标签)
浅谈jQuery使用背景 jQuery是使用原生js写成的一个库,使用简单,提高开发效率.在用js冗杂的代码解决的问题中,大部分都可以用jQuery来快速解决. 例如: js中查询网页中ID为&quo ...
- JVM中垃圾收集选项
最初并发垃圾收集被引入的时候,激活并发垃圾收集的命令选项是: -XX:+UseParallelGC 增强的并行收集和Java 6一起发布,通过一个新的命令行选项: -XX:+UseParallelOl ...
- cesium学习--初识
一.Cesium 官方介绍:CesiumJS是一个开源的JavaScript库,用于世界级的3D地球仪和地图.任务是为静态和时间动态的内容创建领先的3D地球和地图,具有最好的性能.精度.视觉质量.平台 ...
- 最简单的PHP开发环境搭建
近期发现一个非常easy的,适合刚開始学习的人的PHP开发环境,整个环境仅仅有三样东东,PHP ,APACHE , MYSQL可是对于初学PHP的人来说,己经足够了. 假设有兴趣的话能够直接去百度PN ...
- Unity3D研究院之拓展自定义编辑器窗口
Unity支持自行创建窗口,也支持自定义窗口布局.在Project视图中创建一个Editor文件夹,在文件夹中在创建一条脚本. 自定义窗口需要让脚本继承EditorWindow在设置MenuItem, ...
- excel十几万行数据快速导入数据库研究(转,下面那个方法看看还是可以的)
先贴原来的导入数据代码: 8 import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "www.setting ...
- python 基础 7.1 datetime 获得时间
一 datatime 的使用 object timedeta tzinfo time data dat ...