【秦九韶算法】【字符串哈希】bzoj3751 [NOIP2014]解方程
在模意义下枚举m进行验证,多设置几个模数,而且小一些,利用f(x+p)%p=f(x)%p降低计算次数。UOJ AC,bzoj OLE。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
#define MAXV 4951
vector<int>v;
typedef unsigned int ull;
const ull prime[]={4931,4933,4937,4943,4951};
int n;
ull m,a[101][5],F[MAXV+1][5];
char s[10002];
ull f(const ull &x,const int &wh)
{
if(x>=prime[wh]) return f(x%prime[wh],wh);
if(F[x][wh]<MAXV) return F[x][wh];
ull res=0;
for(int i=n;i>=0;--i)
res=(res*x%prime[wh]+a[i][wh])%prime[wh];
return F[x][wh]=res;
}
int main()
{
scanf("%d",&n); cin>>m;
memset(F,0x7f,sizeof(F));
for(int i=0;i<=n;++i)
{
scanf("%s",s);
int len=strlen(s);
for(int k=(s[0]=='-'?1:0);k<len;++k)
for(int j=0;j<5;++j)
a[i][j]=((a[i][j]*10)%prime[j]+(s[k]-'0'))%prime[j];
if(s[0]=='-')
for(int j=0;j<5;++j)
a[i][j]=prime[j]-a[i][j];
}
for(ull i=1;i<=m;++i)
{
for(int j=0;j<5;++j)
if(f(i,j))
goto OUT;
v.push_back((int)i);
OUT:;
}
printf("%d\n",v.size());
for(int i=0;i<v.size();++i) printf("%d\n",v[i]);
return 0;
}
【秦九韶算法】【字符串哈希】bzoj3751 [NOIP2014]解方程的更多相关文章
- [BZOJ3751] [NOIP2014] 解方程 (数学)
Description 已知多项式方程:$a_0+a_1*x+a_2*x^2+...+a_n*x^n=0$ 求这个方程在[1,m]内的整数解(n和m均为正整数). Input 第一行包含2个整数n.m ...
- [BZOJ3751][NOIP2014] 解方程
Description 已知多项式方程:a0+a1*x+a2*x^2+...+an*x^n=0 求这个方程在[1,m]内的整数解(n和m均为正整数). Input 第一行包含2个整数n.m,每两个 ...
- BZOJ3751 NOIP2014 解方程(Hash)
题目链接 BZOJ3751 这道题的关键就是选取取模的质数. 我选了4个大概几万的质数,这样刚好不会T 然后统计答案的时候如果对于当前质数,产生了一个解. 那么对于那些对这个质数取模结果为这个数的数 ...
- [BZOJ3751][NOIP2014]解方程(数学相关+乱搞)
题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...
- 【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】
3751: [NOIP2014]解方程 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4856 Solved: 983[Submit][Status ...
- LOJ2503 NOIP2014 解方程 【HASH】
LOJ2503 NOIP2014 解方程 LINK 题目大意就是给你一个方程,让你求[1,m]中的解,其中系数非常大 看到是提高T3还是解方程就以为是神仙数学题 后来研究了一下高精之类的算法发现过不了 ...
- BZOJ 3751: [NOIP2014]解方程 数学
3751: [NOIP2014]解方程 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3751 Description 已知多项式方程: ...
- bzoj3751 / P2312 解方程
P2312 解方程 bzoj3751(数据加强) 暴力的一题 数据范围:$\left | a_{i} \right |<=10^{10000}$.连高精都无法解决. 然鹅面对这种题,有一种常规套 ...
- NOIP2014解方程
题目:求一个n次整系数方程在1-m内的整数解 n<=100 系数<=10000位 m<=100W 题解:最暴力的想法是枚举x,带入求值看是否为0. 这样涉及到高精度乘高精度,高精度 ...
随机推荐
- Codeforces Round #350 (Div. 2) B
B. Game of Robots time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- hive subprocess failed with code X 的错误码对应信息
PipeMapRed.waitOutputThreads(): subprocess failed with code X ,这里code X对应的信息如下:error code 1: Operati ...
- apply()和call()
每个函数都包含俩个非继承而来的方法:apply() 和 call(),这俩个方法的用途都是在特定的作用域中调用函数,实际上等于设置函数体内this对象的值,以扩充函数赖以运行的作用域.一般来讲,thi ...
- 关于javascript中的this 一段小实例深有体会啊
先声明鄙人正在努力的把脚抬进门来,说的都是比较粗浅的知识,但都是我实践中得出的体会,很深刻. 正在自学中挣扎的DOG. 先看段代码: function highlightRows() { if(!d ...
- [洛谷P1382] 楼房
题目描述 地平线(x轴)上有n个矩(lou)形(fang),用三个整数h[i],l[i],r[i]来表示第i个矩形:矩形左下角为(l[i],0),右上角为(r[i],h[i]).地平线高度为0.在轮廓 ...
- codefoeces 671 problem D
D. Roads in Yusland standard output Mayor of Yusland just won the lottery and decided to spent money ...
- C++11 自动释放锁(转)
原文转自 https://blog.csdn.net/lmb1612977696/article/details/77712170 c++11加入了很多新的特性,值得我们去探索. 先看一个例子:普通的 ...
- 转:SWT中的Display 对象和 Shell对象
转自: http://blog.csdn.net/chulaixi/article/details/3095478 我们书写swt程序的步骤,这些步骤是: 1. 创建一个Display对象 2. 创建 ...
- PHP性能追踪及分析工具xhprof的安装与使用
对于本地开发环境来说,进行性能分析xdebug是够用了,但如果是线上环境的话,xdebug消耗较大,配置也不够灵活,因此线上环境建议使用xhprof进行PHP性能追踪及分析. 我们今天就简单介绍一下x ...
- 【bzoj2086】Blocks
在洛谷上点了个Splay的tag想玩玩,结果看到这题…… #include<bits/stdc++.h> #define N 1000005 using namespace std; ty ...