Bear and Polynomials

题解:

如果改变一个其中的一个数,那么需要知道的是,前面的数都可以进到当前位来,如果过不来的话,那么就会因为前面有数导致无法变成0。

所以我们将前面的数不断向高位转移,找到第一个不能往上进位的位置, p。

现在只有在0 <= i <= p 的时候才有解。

然后我们从高位到地位转移系数。

然后到0 <= i <= p的地方再check合法性。

注意的是,如果当前系数的绝对值  > 2e9, 那么就是不会再出现合法情况了, 因为不可能再变成0了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int a[N];
int n, k;
int solve(){
LL tv = , p = n;
int ret = ;
for(int i = ; i <= n; ++i){
tv = tv / + a[i];
if(tv&){
p = i;
break;
}
}
LL val = ;
for(int i = n; i > p; --i){
val = val * + a[i];
if(abs(val) > INF) {
return ret;
}
}
val = val * + tv;
if(abs(val) > INF) {return ret;}
for(int i = p; i >= ; --i){
if(abs(val - a[i]) <= k){
if(i == n && val == a[i]) ;
else {
++ret;
}
}
val <<= ;
if(abs(val) > INF) {return ret;}
}
return ret;
}
int main(){
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i)
scanf("%d", &a[i]);
printf("%d\n", solve());
return ;
}

最新文章

  1. Winform窗体用对象数组做一个小项目
  2. 设置peoplecode trace
  3. Android判断网络是否已经连接
  4. C# 必应代码搜索
  5. lintcode:Length of Last Word 最后一个单词的长度
  6. php中对共享内存,消息队列的操作
  7. 网页js生成当前年月日 星期
  8. poj 1759 Garland (二分搜索之其他)
  9. Android应用程序安装过程源代码分析
  10. bootstrap 混合标签
  11. 上传图文{"errcode":40007,"errmsg":"invalid media_id"}解决方案
  12. python解释执行原理(转载)
  13. SogouCloud.exe进程导致SQL Server服务无法启动
  14. MySQL 详细学习笔记
  15. python下的MySQL数据库编程
  16. squid介绍和作用
  17. Activity服务类-5 IdentityService服务类
  18. 持续集成与devops
  19. CheckBox使用记录
  20. ContOS网络连接及简单的ssh Xshell连接!

热门文章

  1. 游戏开发3D基础知识
  2. 又一个轮子--QMapper
  3. Hadoop 系列(四)—— Hadoop 开发环境搭建
  4. Tomcat源码分析 (一)----- 手写一个web服务器
  5. 消息中间件-activemq实战之整合Spring(四)
  6. jq css3实现跑马灯+大转盘
  7. Win服务程序编写以及安装一般步骤
  8. CodeForces 29D Ant on the Tree
  9. 并发模型与IO模型梳理
  10. F#周报2019年第33期