Preface Numbering
分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可
/*
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的更多相关文章
- USACO 2.2 Preface Numbering
Preface Numbering A certain book's prefaces are numbered in upper case Roman numerals. Traditional R ...
- 【USACO 2.2】Preface Numbering (找规律)
求 1-n 的所有罗马数字表达中,出现过的每个字母的个数. 分别对每个数的罗马表达式计算每个字母个数. 对于十进制的每一位,都是一样的规则,只是代表的字母不同. 于是我们从最后一位往前考虑,当前位由字 ...
- USACO Section 2.2: Preface Numbering
搬了leetcode的代码 /* ID: yingzho1 LANG: C++ TASK: preface */ #include <iostream> #include <fstr ...
- USACO Preface Numbering 构造
一开始看到这道题目的时候,感觉好难 还要算出罗马的规则. 但是仔细一看,数据规模很小, n 只给到3500 看完题目给出了几组样例之后就有感觉了 解题方法就是: n的每个十进制数 转换成相应的罗马数字 ...
- USACO Section2.2 Preface Numbering 解题报告 【icedream61】
preface解题报告----------------------------------------------------------------------------------------- ...
- Preface Numbering序言页码
题面 (preface.pas/c/cpp) 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M ...
- USACO2.2 Preface Numbering【思维+打表】
这道题乍一看没有什么思路,细看还是没有什么思路 嗯,细看还是可以看出些什么端倪. 不能复合嵌套什么的 总结一下就只有这样3种规则: 1.IXCM最多三个同样连续 加起来2.递减:加起来 注意VLD不连 ...
- p1465 Preface Numbering
用这个函数转成罗马数字统计就行了. #include <iostream> #include <cstdio> #include <cmath> #include ...
- P1465 序言页码 Preface Numbering (手推)
题目描述 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 最多3个同样的可以表示为 ...
随机推荐
- 8.【nuxt起步】-vue组件之间数据交互
那么现在问题来了,我现在是在index.vue获取了服务端的数据,怎么传值到maincontent.vue?当然你也可以把获取数据放在maincontent.vue,但假如有些数据同时在header, ...
- Leanote 二进制版详细安装教程 Windows
https://github.com/leanote/leanote/wiki 本教程适合 Windows 用户的二进制版安装. Windows 用户的源码版安装,参见这里. Mac, Linux 用 ...
- log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'
使用log4net,在win7上可以正常使用,但是在部分xp电脑上可以生成access数据库,但是无法写数据到mdb 排除了程序原因,怀疑是xp缺少什么dll之类的 偶然查到log4net的调试方法: ...
- d3js 画布 概念
HTML 5 提供两种强有力的“画布”:SVG 和 Canvas. SVG 有如下特点: SVG 绘制的是矢量图,因此对图像进行放大不会失真. 基于 XML,可以为每个元素添加 JavaScript ...
- openERP server action,最强大的功能,没有之一
Jeffery9@gmail.com 出品 @jeffery-陈帆 原理 ations OE定义了ir.actions.actions,并从中派生了众多的子类 ir.actions.client ir ...
- dos alias/cname address
diego@localhost sdk/include/Poco/Net]# dig b.wpss.cn ; <<>> DiG - <<>> b.wps ...
- 自己定义struts2中action类型转换器
DateAction.java中代码例如以下: package com.itheima.action; import java.util.Date; public class DateAction { ...
- 递归计算战士打靶S次打了N环一共同拥有多少种可能的问题
问题描写叙述 一个战士打了10次靶.一共打了90环,问一共同拥有多少种可能,并输出这些可能的组合. 思路 首先.嵌套10层循环进行穷举是不可取的,一是由于速度太慢,二是假设改成打20次靶就完蛋了. 事 ...
- Linux CenOS Python3 和 python2 共存
1.查看是否已经安装Python CentOS 7.2 默认安装了python2.7.5 因为一些命令要用它比如yum 它使用的是python2.7.5. 使用 python -V 命令查看一下是否安 ...
- String.split()分割字符串方法
split方法的主要用处就是:分割字符串 split方法返回的是数组类型 主要由以下几种用法: 1.比如有一个字符串var str = "bcadeab";对str使用split方 ...