链接

分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可

 /*
PROB:preface
ID:wanghan
LANG:C++
*/
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "map"
using namespace std;
const int maxn=;
char s[]={'I','V','X','L','C','D','M'};
int h[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
int n;
struct Node{
int x;
string str;
};
Node p[maxn];
map<int,string> mp;
void init(){
mp[]="I",mp[]="II",mp[]="III",mp[]="IV",mp[]="V",mp[]="VI",mp[]="VII",mp[]="VIII",mp[]="IX";
mp[]="X",mp[]="XX",mp[]="XXX",mp[]="XL",mp[]="L",mp[]="LX",mp[]="LXX",mp[]="LXXX",mp[]="XC";
mp[]="C",mp[]="CC",mp[]="CCC",mp[]="CD",mp[]="D",mp[]="DC",mp[]="DCC",mp[]="DCCC",mp[]="CM";
mp[]="M",mp[]="MM",mp[]="MMM";
}
string solve(int num){
string res="";
while(num){
int pos=-;
for(int i=;i>=;i--){
if(num>=h[i]){
pos=i; break;
}
}
int mod=num/h[pos];
for(int i=;i<=mod;i++){
num-=h[pos];
res+=mp[h[pos]];
}
//num-=h[pos];
//res+=mp[h[pos]];
}
return res;
}
map<char,int>mr;
int main()
{
freopen("preface.in","r",stdin);
freopen("preface.out","w",stdout);
cin>>n;
init();
for(int i=;i<=n;i++){
p[i].x=i;
p[i].str=solve(i);
//cout<<i<<": ";
//cout<<p[i].str<<endl;
}
for(int i=;i<=n;i++){
for(int j=;j<p[i].str.length();j++){
mr[p[i].str[j]]++;
}
}
for(int i=;i<;i++){
if(mr[s[i]]==) continue;
else{
cout<<s[i]<<" "<<mr[s[i]]<<endl;
}
}
return ;
}

Preface Numbering的更多相关文章

  1. USACO 2.2 Preface Numbering

    Preface Numbering A certain book's prefaces are numbered in upper case Roman numerals. Traditional R ...

  2. 【USACO 2.2】Preface Numbering (找规律)

    求 1-n 的所有罗马数字表达中,出现过的每个字母的个数. 分别对每个数的罗马表达式计算每个字母个数. 对于十进制的每一位,都是一样的规则,只是代表的字母不同. 于是我们从最后一位往前考虑,当前位由字 ...

  3. USACO Section 2.2: Preface Numbering

    搬了leetcode的代码 /* ID: yingzho1 LANG: C++ TASK: preface */ #include <iostream> #include <fstr ...

  4. USACO Preface Numbering 构造

    一开始看到这道题目的时候,感觉好难 还要算出罗马的规则. 但是仔细一看,数据规模很小, n 只给到3500 看完题目给出了几组样例之后就有感觉了 解题方法就是: n的每个十进制数 转换成相应的罗马数字 ...

  5. USACO Section2.2 Preface Numbering 解题报告 【icedream61】

    preface解题报告----------------------------------------------------------------------------------------- ...

  6. Preface Numbering序言页码

    题面 (preface.pas/c/cpp) 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M ...

  7. USACO2.2 Preface Numbering【思维+打表】

    这道题乍一看没有什么思路,细看还是没有什么思路 嗯,细看还是可以看出些什么端倪. 不能复合嵌套什么的 总结一下就只有这样3种规则: 1.IXCM最多三个同样连续 加起来2.递减:加起来 注意VLD不连 ...

  8. p1465 Preface Numbering

    用这个函数转成罗马数字统计就行了. #include <iostream> #include <cstdio> #include <cmath> #include ...

  9. P1465 序言页码 Preface Numbering (手推)

    题目描述 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 最多3个同样的可以表示为 ...

随机推荐

  1. 【Todo】各种语言里面的for循环 & loop

    会的语言多了,不同语言的语法就会混淆.整理了一下. Java里面: 普通的for循环之外: 有以下格式: for (int x : intarr) { } JS里面: }; for (x in per ...

  2. [Algorithms] Sort an Array with a Nested for Loop using Insertion Sort in JavaScript

    nsertion sort is another sorting algorithm that closely resembles how we might sort items in the phy ...

  3. Cookie学习笔记二:Cookie实例

    今天说说刚刚学到的两个Cookie的最经典应用:自己主动登录和购物车设置 一:自己主动登录 须要两个页面:login.jsp与index.jsp,login.jsp用来输出登录信息,index.jsp ...

  4. word中更改图片和标题之间的垂直距离

    word中插入图片后.往往须要给图片加上标题. 你插入图片和给图片插入标题时,word用的是默认的格式给你插入的图片和标题. 假如原来的paragraph是2倍行距.你的图片和标题之间的距离也是2倍行 ...

  5. vue 给组件绑定原生事件

    有时候,你可能想在某个组件的根元素上监听一个原生事件.可以使用 v-on 的修饰符 .native.例如: <my-component v-on:click.native="doThe ...

  6. 有关C/C++指针的经典面试题(转)

    参考一: 有关C/C++指针的经典面试题 0.预备知识,最基础的指针 其实最基础的指针也就应该如下面代码: int a; int* p=&a; 也就是说,声明了一个int变量a,然后声明一个i ...

  7. meta标签多种用法

    <meta name=”google” content=”notranslate” /> <!-- 有时,Google在结果页面会提供一个翻译链接,但有时候你不希望出现这个链接,你可 ...

  8. Solaris 系统启动与关闭

    忘掉root密码 更改内核参数后,重启进不了系统 复制---进入单用户模式----恢复文件 系统突然死机,如何尽量减少数据丢失 Sync 同步命令.将内存内容输入到硬盘,相当于保存文档.   Unix ...

  9. AVOS Cloud 技术支持系统开源了

    非常高兴跟大家说.工单系统(技术支持系统)开源了.代码托管在了Github上. 假设还未见识过工单系统,请移步于 https://ticket.avosapps.com/ 这个系统是用 AVOS Cl ...

  10. Linux下查看系统CPU个数、核心数、线程数

    1.查看物理CPU个数 (env) root@vmware01:~# grep 'physical id' /proc/cpuinfo physical physical physical physi ...