日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

BZOJ1970 [Ahoi2005] 矿藏编码

發布時間:2025/3/17 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ1970 [Ahoi2005] 矿藏编码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

依次對每份進行編碼,得S1,S2,S3,S4。該礦藏區的編碼S為2S1S2S3S4。 例如上圖中,礦藏區的編碼為:2021010210001。 小聯希望你能根據給定的編碼統計出這片礦藏區一共有多少格子區域是平地。

Input

第一行有一個整數K,表示有礦藏區的規模為 (1 < K < 50)。第二行有一串編碼,有0、1組成,長度不超過200,表示該礦藏區的編碼。

Output

單行輸出一個整數,表示礦藏區中一共有多少格子是平地。

Sample Input

2
2021010210001

Sample Output

9

題解

這題挺簡單?;旧蠈懸粋€高精度就能解決。

代碼:

#include <cctype> #include <cstdio> const int K = 105; int A[100]; int a[K]; inline int get() {int c;while (!isdigit(c = getchar()));return c - '0'; } void solve(int dep) {int t = get();if (t == 0)++a[dep * 2];else if (t == 2) {solve(dep - 1);solve(dep - 1);solve(dep - 1);solve(dep - 1);} } int main() {int k;scanf("%d", &k);solve(k);int len = 1;for (int i = 0; i < k * 2; ++i) {a[i + 1] += a[i] / 2;a[i] %= 2;}for (int i = k * 2; ~i; --i) {int t;for (int j = t = 0; j < len; ++j) {t = (A[j] = A[j] * 2 + t) / 10;A[j] %= 10;}if (t) A[len++] = t;if (a[i]) ++A[0];}while (len--) putchar(A[len] + '0');putchar('\n');return 0; }

 ps:上微機課寫題好爽。拿notepad(沒有++)寫題好有趣。

轉載于:https://www.cnblogs.com/y-clever/p/7645021.html

總結

以上是生活随笔為你收集整理的BZOJ1970 [Ahoi2005] 矿藏编码的全部內容,希望文章能夠幫你解決所遇到的問題。

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