链接

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

 /*
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. Mac 安装配置Mysql

    Mac下安装配置Mysql By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明出处,谢谢. 下载安装 去官网下载Community版本号的mysql安装文件. ...

  2. eclipse中文凝视字体太小解决方法

    新安装的eclipse中文凝视字体太小.解决方法例如以下: 打开Elcipse-->点击菜单条上的"Windows"-->点击"Preferences&quo ...

  3. 使用 rman duplicate from active database 搭建dataguard 手记--系列二

    run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 typ ...

  4. 从零開始开发Android版2048 (二)获取手势信息

    今天是尝试開始Android版2048小游戏的第二天.在今天,我主要学习了怎样获取用户在屏幕滑动的手势,以及对布局进行了一些小小的完好. 获取用户操作的手势(比方向左滑.向右滑等)主要用到了Gestu ...

  5. Vue 字面量语法 vs 动态语法

    初学者常犯的一个错误是使用字面量语法传递数值: <!-- 传递了一个字符串 "1" --> <comp some-prop="1">&l ...

  6. 搭建windows下的odoo开发环境

    odoo运行环境的必须要要求是 python环境 postgreSQL数据 数据库可以安装在别的机器上,比如服务器:当然对于开发环境,通常,数据库与代码调试安装在同一台机器上. 首先安装 postgr ...

  7. HDMI各版本对比

    转:一文看懂从HDMI1.0到HDMI2.1的历代规格变化 hdmi HDMI详解 https://blog.csdn.net/xubin341719/article/details/7713450 ...

  8. openwrt spi flash 分区适配过程

    openwrt spi flash 分区适配过程 这里基于 openwrt mt7620a 平台来跟踪,主要是想理清 dts 里的分区描述是如何一步步转化成内核分区行为. 先来看看 dts 中关于分区 ...

  9. idea分支合并

    1.切换到指定分支(例如dev) 2.点击master的merge进行合并 注意:最好删掉本地的master和dev然后重新拉下远程的master和dev生成最新的本地master和dev

  10. esri和ArcGIS

    1 esri esri是environment system research institute,环境系统研究所.总部在美国加州.它是世界上最大的GIS技术提供商. 主要产品有ArcGIS.ArcV ...