Problem

P2312 【解方程】 >>>

record

  • 用时: 1166ms
  • 空间: 780KB(0.76MB)
  • 代码长度: 2.95KB
  • 提交记录: R9909587 >>>
  • 注: 使用了
    1. o1 优化
    2. o2 优化
    3. o3 优化
    4. 快读快输 >>>

Solution

30 pts

枚举,使用 int,直接按题目所说暴力乱搞一通

Unaccepted 30
Ac:3
Wa:7

50 pts

∣a_i∣≤10^10000

所以高精度。

然而慢的一皮:

Unaccepted 50
Ac:5
Tle:5

评测记录 >>>

30 pts

考虑暴力优化。

考虑在模意义下进行暴力,可以减小误差。

注意:模的应该是质数,且应该多模数,防止误差。

质数应该多记住几个,考场上的时候很有用(如:哈希)

然后。。。就出锅了。

评测记录 >>>

Unaccepted 30
Ac:3
Wa:7

100 pts

请大家在NOIp上一定要:开 long long!

评测记录 >>>

Accepted 100
Ac:10

Code

// luogu-judger-enable-o2
/**
* Problem: P2312 解方程.
* Author: 航空信奥.
* Date: 2018/08/19.
* Upload: Luogu.
*/
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <stdio.h>
#include <vector>
using namespace std; namespace hkxadpall { char BufferRead[1 << 15];
int rLen = 0, rPos = 0;
inline char Getchar()
{
if (rPos == rLen) rPos = 0, rLen = fread(BufferRead, 1, 1 << 15, stdin);
if (rPos == rLen) return EOF;
return BufferRead[rPos++];
} template <typename _TpInt> inline _TpInt read();
template <typename _TpInt> inline void write(_TpInt x); # define Max_N 103
# define Mod1 10007LL
# define Mod2 19260817LL
# define Mod3 100000007LL int n, m;
long long a1[Max_N];
long long a2[Max_N];
long long a3[Max_N]; bool isRight(long long *a, int x, long long mod)
{
long long ans = a[n];
for (int i = n - 1; i >= 0; i--) {
ans = (ans * x + a[i]) % mod;
}
return (ans == 0);
} int main()
{
n = read<int>();
m = read<int>(); for (int i = 0; i <= n; i++) {
bool flag = 0;
char c = Getchar();
while ((c > '9' || c < '0') && c != '-')
c = Getchar();
if (c == '-') flag = 1, c = Getchar();
a1[i] = (c & 15);
a2[i] = (c & 15);
a3[i] = (c & 15);
while ((c = Getchar()) <= '9' && c >= '0') {
a1[i] = ((a1[i] * 10) + (c & 15)) % Mod1;
a2[i] = ((a2[i] * 10) + (c & 15)) % Mod2;
a3[i] = ((a3[i] * 10) + (c & 15)) % Mod3;
}
if (flag) {
a1[i] = Mod1 - a1[i];
a2[i] = Mod2 - a2[i];
a3[i] = Mod3 - a3[i];
}
} vector <int> answer;
for (int i = 1; i <= m; i++) {
if (isRight(a1, i, Mod1)
&& isRight(a2, i, Mod2)
&& isRight(a3, i, Mod3))
answer.push_back(i);
} printf("%d\n", answer.size());
for (int i = 0; i < answer.size(); i++)
write(answer[i]), putchar(10); return 0;
} template <typename _TpInt>
inline _TpInt read()
{
register int flag = 1;
register char c = Getchar();
while ((c > '9' || c < '0') && c != '-')
c = Getchar();
if (c == '-') flag = -1, c = Getchar();
register _TpInt init = (c & 15);
while ((c = Getchar()) <= '9' && c >= '0')
init = (init << 3) + (init << 1) + (c & 15);
return init * flag;
} template <typename _TpInt>
inline void write(_TpInt x)
{
if (x < 0) {
putchar('-');
write<_TpInt>(~x + 1);
}
else {
if (x > 9) write<_TpInt>(x / 10);
putchar(x % 10 + '0');
}
}
} int main()
{
hkxadpall::main();
return 0;
}

洛谷 题解 P2312 【解方程】的更多相关文章

  1. luogu题解P2312解方程--暴力模+秦九韶

    题目链接 https://www.luogu.org/problemnew/show/P2312 分析 这道题很毒啊,这么大的数. 但是如果多项式\(\sum_{i=0}^N a[i]*X^i=0\) ...

  2. 洛谷P2312 解方程题解

    洛谷P2312 解方程题解 题目描述 已知多项式方程: \[a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\] 求这个方程在 \([1,m]\) 内的整数解(\(n\) 和 \(m\) ...

  3. 洛谷 P2312 解方程 题解

    P2312 解方程 题目描述 已知多项式方程: \[a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\] 求这个方程在 [1,m][1,m] 内的整数解(\(n\) 和 \(m\) 均为 ...

  4. codevs3732==洛谷 解方程P2312 解方程

    P2312 解方程 195通过 1.6K提交 题目提供者该用户不存在 标签数论(数学相关)高精2014NOIp提高组 难度提高+/省选- 提交该题 讨论 题解 记录   题目描述 已知多项式方程: a ...

  5. 洛谷 P2312 解方程 解题报告

    P2312 解方程 题目描述 已知多项式方程: \(a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\)求这个方程在 \([1,m]\) 内的整数解(\(n\) 和 \(m\) 均为正整 ...

  6. bzoj3751 / P2312 解方程

    P2312 解方程 bzoj3751(数据加强) 暴力的一题 数据范围:$\left | a_{i} \right |<=10^{10000}$.连高精都无法解决. 然鹅面对这种题,有一种常规套 ...

  7. [noip2014]P2312 解方程

    P2312 解方程 其实这道题就是求一个1元n次方程在区间[1, m]上的整数解. 我们枚举[1, m]上的所有整数,带进多项式中看看结果是不是0即可. 这里有一个技巧就是秦九韶算法,请读者自行查看学 ...

  8. P2312 解方程(随机化)

    P2312 解方程 随机化的通俗解释:当无法得出100%正确的答案时,考虑随机化一波,于是这份代码很大可能会对(几乎不可能出错). 比如这题:把系数都模一个大质数(也可以随机一个质数),然后O(m)跑 ...

  9. 洛谷 题解 P1600 【天天爱跑步】 (NOIP2016)

    必须得说,这是一道难题(尤其对于我这样普及组205分的蒟蒻) 提交结果(NOIP2016 天天爱跑步): OJ名 编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间 Libre ...

随机推荐

  1. 重写equals方法,也应该重写hashcode方法,反之亦然

    yls 2019年11月07日 一方面 hashcode原则:两个对象equals相等,hashcode值一定相等 默认的hashcode是Object类通过对象的内存地址得到的 若重写equals而 ...

  2. 创建基于OData的Web API - Knowledge Builder API, Part IV: Write Controller

    基于上一篇<创建基于OData的Web API - Knowledge Builder API, Part III:Write Model and Controller>,新创建的ODat ...

  3. nyoj 50-爱摘苹果的小明 (比较)

    50-爱摘苹果的小明 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:10 submit:15 题目描述: 小明家的院子里有一棵苹果树,每到秋天树上就 ...

  4. 文件系统类型(ext4、xfs、fat32、vfat、ntfs、....)

    Linux 1.Linux:存在几十个文件系统类型:ext2,ext3,ext4,xfs,brtfs,zfs(man 5 fs可以取得全部文件系统的介绍) 不同文件系统采用不同的方法来管理磁盘空间,各 ...

  5. 痞子衡嵌入式:飞思卡尔Kinetis系列MCU启动那些事(10)- KBOOT特性(可靠升级)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔Kinetis系列MCU的KBOOT之可靠升级(Reliable Update)特性. 所谓可靠升级机制,即在更新Applica ...

  6. python高阶函数的使用

    目录 python高阶函数的使用 1.map 2.reduce 3.filter 4.sorted 5.小结 python高阶函数的使用 1.map Python内建了map()函数,map()函数接 ...

  7. C语言程序设计100例之(17):百灯判亮

    例17   百灯判亮 问题描述 有序号为1.2.3.….99.100的100盏灯从左至右排成一横行,且每盏灯各由一个拉线开关控制着,最初它们全呈关闭状态.有100个小朋友,第1位走过来把凡是序号为1的 ...

  8. C# 彻底搞懂async/await

    前言 Talk is cheap, Show you the code first! private void button1_Click(object sender, EventArgs e) { ...

  9. SoapUI使用JDBC请求连接数据库及断言的使用

    SoapUI提供了用来配置JDBC数据库连接的选项,因此我们可以在测试中使用JDBC数据源.JDBC数据接收器和JDBC请求步骤. 为了能够配置数据连接,就必须有驱动程序和连接串,SoapUI中已经提 ...

  10. centos7 设置连接无线wifi

    安装系统后,首先要联网. 1.首先使用网线连接,之后尝试ping www.baidu.com我的是自动通的 2.需要查看网卡型号,先安装工具 yum -y install pciutils* 3.查看 ...