题目链接:

D. Bear and Polynomials

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0.

Examples
input
3 1000000000
10 -9 -3 5
output
3
input
3 12
10 -9 -3 5
output
2
input
2 20
14 -7 19
output
0
Note

In the first sample, we are given a polynomial P(x) = 10 - 9x - 3x2 + 5x3.

Limak can change one coefficient in three ways:

  1. He can set a0 =  - 10. Then he would get Q(x) =  - 10 - 9x - 3x2 + 5x3 and indeed Q(2) =  - 10 - 18 - 12 + 40 = 0.
  2. Or he can set a2 =  - 8. Then Q(x) = 10 - 9x - 8x2 + 5x3 and indeed Q(2) = 10 - 18 - 32 + 40 = 0.
  3. 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(数学)的更多相关文章

  1. CodeForces 639C Bear and Polynomials

    Bear and Polynomials 题解: 如果改变一个其中的一个数,那么需要知道的是,前面的数都可以进到当前位来,如果过不来的话,那么就会因为前面有数导致无法变成0. 所以我们将前面的数不断向 ...

  2. 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 ...

  3. Codeforces 658D Bear and Polynomials【数学】

    题目链接: http://codeforces.com/contest/658/problem/D 题意: 给定合法多项式,改变一项的系数,使得P(2)=0,问有多少种方法? 分析: 暴力求和然后依次 ...

  4. Codeforces 902D/901B - GCD of Polynomials

    传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如 ...

  5. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. Codeforces 735C:Tennis Championship(数学+贪心)

    http://codeforces.com/problemset/problem/735/C 题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局.问这n个人里面冠军最多能赢多少场, ...

  7. 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 ...

  8. codeforces 680B B. Bear and Finding Criminals(水题)

    题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...

  9. codeforces 680A A. Bear and Five Cards(水题)

    题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...

随机推荐

  1. objc_msgSend 报错

    NSMutableArray * mutableArray = [NSMutableArray arrayWithArray:array]; objc_msgSend(mutableArray,@se ...

  2. Mode Standby

    Modern Standby 1.Connected Standby和 Connected Standby是Windows 8全新的电源管理系统,即当系统进入休眠状态时,应用程式虽处於暂停(suspe ...

  3. Java 8 Collectors to Map

    1. 介绍 在本教程中,我们将讨论Collectors类的toMap()方法.我们使用它将流收集到一个Map实例中. 对于本教程中涉及的所有示例,我们将使用图书列表作为数据源,并将其转换为不同的Map ...

  4. gulp 静态资源版本控制

    package.json { "name": "gulp", "version": "0.0.1", "des ...

  5. HTML5 2D平台游戏开发#3冲刺

    断断续续地把Demo又写了一阵,终于把角色的冲刺动作完成了.冲刺的作用是使角色能够快速移动,闪避攻击或障碍.其完成效果如下: 首先,仍需要一些变量来表示角色的冲刺状态: //标识角色是否处于冲刺中 v ...

  6. vsftpd 虚拟用户限定在虚拟用户目录

    1.安装vsftpd yum -y install pam pam-devel db4 db4-tcl vsftpd 2.更名默认配置文件,以便恢复 cp /etc/vsftpd/vsftpd.con ...

  7. 玩转 eclipse:[1]如何快速找错-debug

    本文摘自百度经验 原文地址如下: 玩转 eclipse:[1]如何快速找错-debu eclipse是软件开发人员必备的IDE之一. 由于语言障碍或者是经验不足,许多刚刚新手并不清楚如何高效使用ecl ...

  8. iis出现HTTP 错误 403.14 - Forbidden Web问题

    找到"目录浏览",并"应用"

  9. JS 之 数据类型转换

          首先我们来简单了解一下JS中的数据类型,JavaScript拥有字符串.数字.布尔.数组.对象.Null.Undefiend 6中数据类型.同一时候,JavaScript拥有动态类型. 也 ...

  10. ios何时使用self.

     本文转载至  http://blog.csdn.net/lvxiangan/article/details/27204265   何时使用self.在网上搜索或者论坛里的回复大多都是简简单单的说这与 ...