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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

USACO-Section2.2 Preface Numbering

發布時間:2025/3/15 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USACO-Section2.2 Preface Numbering 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2017-8-30

題目描述

序言的頁碼數,請統計在第1頁到第N頁中,有幾個I出現,幾個V出現...

解答

將已知存起來,不再重復計算,沒有求的用已經求好的加起來

代碼

/* ID: 18795871 PROG: preface LANG: C++ */ #include<iostream> #include<fstream> #include<cstring> using namespace std; const int N = 3500;ifstream fin("preface.in"); ofstream fout("preface.out");string x[N+1]; bool f[N+1]; //避免重復計算 int cnt[7]; char y[7]={'I','V','X','L','C','D','M'}; int n;void init(){int i;x[1]="I";x[10]="X";x[100]="C";x[1000]="M";x[5]="V";x[50]="L";x[500]="D";x[2]="II";x[20]="XX";x[200]="CC";x[2000]="MM";x[3]="III";x[30]="XXX";x[300]="CCC";x[3000]="MMM";x[4]="IV";x[40]="XL";x[400]="CD";x[6]="VI";x[60]="LX";x[600]="DC";x[7]="VII";x[70]="LXX";x[700]="DCC";x[8]="VIII";x[80]="LXXX";x[800]="DCCC";x[9]="IX";x[90]="XC";x[900]="CM";for (int i=1;i<=10;i++){f[i]=true;f[i*10]=true;f[i*100]=true;}f[2000]=true;f[3000]=true; }void cal(int m){if (f[m]) return ;f[m]=true; if (m<100){int s=m/10;int g=m%10;x[m]=x[s*10]+x[g];}else if (m<1000){int b=m/100;x[m]=x[b*100]+x[m-b*100];}else{int q=m/1000;x[m]=x[q*1000]+x[m-q*1000];}return ; }int main(){fin>>n;int i,j;init();memset(f,false,sizeof(f));for (i=1;i<=n;i++){cal(i);}for (i=1;i<=n;i++){for (j=0;j<=x[i].length();j++){switch(x[i][j]){case 'I':cnt[0]++;break;case 'V':cnt[1]++;break;case 'X':cnt[2]++;break;case 'L':cnt[3]++;break;case 'C':cnt[4]++;break;case 'D':cnt[5]++;break;case 'M':cnt[6]++;break;}}} for (i=0;i<7;i++){if (cnt[i]){fout<<y[i]<<" "<<cnt[i]<<endl;}}return 0; }

總結

以上是生活随笔為你收集整理的USACO-Section2.2 Preface Numbering的全部內容,希望文章能夠幫你解決所遇到的問題。

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