vijos - P1077複製龍 (找規律 + 指數型母函數 + python)

來源:互聯網
上載者:User

標籤:

P1077複製龍Accepted標籤:[顯示標籤]描述

現在龍的複製已成為可能,龍基因由ACTG字母組成,而龍的基因有如下特點:
1、A在基因中的出現為偶數次(包括0);
2、C的情況也一樣;
當n=2時 滿足條件的有6個:
TT,TG,GT,GG,AA,CC
你只需給出滿足條件的基因數的最後兩位元字即可;

格式輸入格式

輸入檔案給出了若干個n(1<=n<=10^9).最後以0結束。

輸出格式

對於輸入的n,滿足條件的字串的個數的最後兩位元字!

範例1範例輸入1[複製]
1230
範例輸出1[複製]
2620
來源

huyichen

找規律就可,指數型母函數稍後上傳

這裡的零應該進行特殊處理,比較坑

用python直接就是個遞推式



#!/usr/bin/env python3# -*- coding: utf-8 -*-import mathimport sysfor cin in sys.stdin:    n = long(cin)    if not n:break    n -= 1    a = math.ceil(pow(2, n, 100) * (pow(2, n, 100) + 1))    a = long(a)    if a % 100 == 0:        print '00'    else:        print a % 100

C++:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;int a[11] = {2,6,20,72,72,56,60,12,92,56};int b[21] = {0,52,12,56,40,92,32,56,80,32,52,56,20,72,72,56,60,12,92,56};int main() {    int n;    while(~ scanf("%I64d", &n),n) {        if(n <= 10) {            n -- ;            printf("%d\n",a[n]);        } else {            if(b[(n - 11) % 20] == 0) printf("00\n");            else printf("%d\n",b[(n - 11) % 20]);        }    }    return 0;}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

vijos - P1077複製龍 (找規律 + 指數型母函數 + python)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.