洛谷 题解 P2312 【解方程】
生活随笔
收集整理的這篇文章主要介紹了
洛谷 题解 P2312 【解方程】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Problem
P2312 【解方程】 >>>
record
- 用時: 1166ms
- 空間: 780KB(0.76MB)
- 代碼長度: 2.95KB
- 提交記錄: R9909587 >>>
- 注: 使用了
- o1 優化
- o2 優化
- o3 優化
- 快讀快輸 >>>
Solution
30 pts
枚舉,使用 int,直接按題目所說暴力亂搞一通
Unaccepted 30 Ac:3 Wa:750 pts
∣a_i∣≤10^10000
所以高精度。
然而慢的一皮:
Unaccepted 50 Ac:5 Tle:5評測記錄 >>>
30 pts
考慮暴力優化。
考慮在模意義下進行暴力,可以減小誤差。
注意:模的應該是質數,且應該多模數,防止誤差。
質數應該多記住幾個,考場上的時候很有用(如:哈希)
然后。。。就出鍋了。
評測記錄 >>>
Unaccepted 30 Ac:3 Wa:7100 pts
請大家在NOIp上一定要:開 long long!
評測記錄 >>>
Accepted 100 Ac:10Code
// 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 100000007LLint 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; }轉載于:https://www.cnblogs.com/hkxadpall/p/9895943.html
總結
以上是生活随笔為你收集整理的洛谷 题解 P2312 【解方程】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓网页离线保存_Android web
- 下一篇: Spark在Ambari集群环境的使用