国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

hdu1041【找規(guī)律】

2019-11-11 02:05:36
字體:
供稿:網(wǎng)友

Computer Transformation

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7862 Accepted Submission(s): 2942

PRoblem Description A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on.

How many pairs of consequitive zeroes will appear in the sequence after n steps?

Input Every input line contains one natural number n (0 < n ≤1000).

Output For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.

Sample Input 2 3

Sample Output 1 1

題解:計(jì)算機(jī)能把1變成01,0變成10,問第n步后00的個(gè)數(shù) step0:1 step1:0 1 step2:10 01 step3:0110 1001 step4:1001 0110 0110 1001 step5:0110 1001 1001 0110 1001 0110 0110 1001 第n步的00由n-1步的01變化而來,第n-1步的01則由n-2步的1變化而來 除此之外,第n-2步的00->1010->01100110也貢獻(xiàn)一個(gè)00 所以F(n)=F(n-2)+2^(n-3)(即n-2步里1的個(gè)數(shù))

代碼:

#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#define MST(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 9999using namespace std;int a[1005][1001];//F(n) = F(n - 2) + 2 ^ (n - 3);void deal(){ MST(a, 0); a[0][1] = 1; a[1][1] = 0, a[2][1] = 1, a[3][1] = 1; for (int i = 4; i <= 1000; i++) { int r = 0; for (int j = 1; j <= 1000; j++) { a[0][j] *= 2; a[0][j] += r; r = 0; if (a[0][j] > 9) { r = 1; a[0][j] -= 10; } } r = 0; for (int j = 1; j <= 1000; j++) { a[i][j] = a[i - 2][j] + a[0][j] + r;; r = 0; if (a[i][j] > 9) { r = 1; a[i][j] -= 10; } } }}int main(){ deal(); int n; while (cin >> n) { if (n == 1) { cout << 0 << endl; continue; } int i = 1000; while (a[n][i] == 0)i--; for (; i >= 1; i--) printf("%d", a[n][i] ); printf("/n"); }}
上一篇:servlet 的亂碼問題

下一篇:cpp12.10

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁远县| 青海省| 屏东市| 景宁| 股票| 抚顺县| 青海省| 鞍山市| 紫阳县| 广丰县| 颍上县| 清河县| 遂昌县| 木兰县| 阳朔县| 北碚区| 惠州市| 射阳县| 哈密市| 英超| 冷水江市| 曲水县| 扬州市| 南汇区| 库车县| 乌兰浩特市| 陆良县| 读书| 东阳市| 苗栗市| 乌兰察布市| 民权县| 新余市| 辽宁省| 奉节县| 珲春市| 东海县| 敖汉旗| 离岛区| 应用必备| 上虞市|