日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

HDU 5047 Sawtooth 高精度

發布時間:2023/11/27 生活经验 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 5047 Sawtooth 高精度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

給出一個\(n(0 \leq n \leq 10^{12})\),問\(n\)\(M\)形的折線最多可以把平面分成幾部分。

分析:

很容易猜出來這種公式一定的關于\(n\)的一個二次多項式。
不妨設\(f(n)=an^2+bn+c\)
結合樣例我們可以列出\(3\)個方程:
\(f(0)=1,f(1)=2,f(2)=19\)
解出三個系數\(a,b,c\),然后用高精度做即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;typedef long long LL;const LL MOD = 1000000000;struct Big
{LL a[5];Big() { memset(a, 0, sizeof(a)); }Big(LL x) { memset(a, 0, sizeof(a)); a[1] = x / MOD; a[0] = x % MOD; }void read() {memset(a, 0, sizeof(a));LL x; scanf("%lld", &x);a[0] = x % MOD; a[1] = x / MOD;}Big operator + (const Big& t) const {Big ans;for(int i = 0; i < 5; i++) ans.a[i] = a[i];for(int i = 0; i < 5; i++) {ans.a[i] += t.a[i];int j = i;while(ans.a[j] >= MOD) {ans.a[j + 1] += ans.a[j] / MOD;ans.a[j++] %= MOD;}}return ans;}Big operator * (const Big& t) const {Big ans;for(int i = 0; i < 5; i++) {for(int j = 0; j < 5; j++) if(i + j < 5) {ans.a[i + j] += a[j] * t.a[i];int k = i + j;while(ans.a[k] >= MOD) {ans.a[k + 1] += ans.a[k] / MOD;ans.a[k++] %= MOD;}}}return ans;}Big operator - (const Big& t) const {Big ans;for(int i = 0; i < 5; i++) ans.a[i] = a[i];for(int i = 0; i < 5; i++) {int j = i + 1;if(ans.a[i] < t.a[i]) {while(!ans.a[j]) j++;ans.a[j]--;for(int k = j - 1; k > i; k--) ans.a[k] += MOD - 1;ans.a[i] += MOD;}ans.a[i] -= t.a[i];}return ans;}void output() {int i = 0;for(i = 4; i; i--) if(a[i]) break;printf("%lld", a[i]);for(int j = i - 1; j >= 0; j--) printf("%09lld", a[j]);printf("\n");}
};int main()
{int T; scanf("%d", &T);for(int kase = 1; kase <= T; kase++) {printf("Case #%d: ", kase);Big x; x.read();Big ans(1);ans = ans + (Big(8) * x * x);ans = ans - (Big(7) * x);ans.output();}return 0;
}

轉載于:https://www.cnblogs.com/AOQNRMGYXLMV/p/5274412.html

總結

以上是生活随笔為你收集整理的HDU 5047 Sawtooth 高精度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。