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个同样的可以表示为 ...
随机推荐
- GDB调试动态链接库
http://cyukang.com/2012/06/25/gdb-with-libso.html http://cyukang.com/2011/05/06/valgrind.html
- 转:国内外著名开源b2c电子商务系统比较包括asp.net和php
from: http://longdick.iteye.com/blog/1122879 国内外著名开源b2c电子商务系统比较包括asp.net和php 博客分类: 电子商务 国内外著名开源b2c ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- python(39)- 网络编程socket练习
基于tcp的套接字实现远程执行命令的操作 #服务端 import socket import subprocess phone=socket.socket(socket.AF_INET,socket. ...
- (利用DOM)在新打开的页面点击关闭当前浏览器窗口
1.在开发过程中我们前端的用户体验中有时候会要求点击一个按钮,关闭当前浏览器窗口,用HTML DOM就可做到 2.注意:本次写法要求在新窗口中关闭.target="_blank" ...
- python 调用函数时使用星号 *, **
python 调用函数时使用星号 *, ** 调用函数时使用星号 * 或 ** test(*args):* 的作用其实就是把序列 args 中的每个元素,当作位置参数传进去.如果 args 等于 (1 ...
- ZYThumbnailTableView---堪比一个小型阅读App
Demo github地址: https://github.com/liuzhiyi1992/ZYThumbnailTableView 原文地址:http://zyden.vicp.cc/zythum ...
- 晶振及COMS电路
COMS电路:http://www.docin.com/p-246885507.html 简介:无源晶振和有源晶振 电子线路中的晶体振荡器也分为无源晶振和有源晶振两种类型.无源晶振与有源晶振的英文名称 ...
- C++编译错误 2001 1120
无法解析的外部符号"symbol" 代码引用了链接器无法在库和对象文件中找到的内容(如函数.变量或标签). 该错误信息之后为错误 LNK1120. 可能的原因 : 在将托管库或 W ...
- class中的私有属性的访问
在类中的私有属性设置: class Name(): __init__(self): self.__name = 'arnol'` 如何查看: 1,在类中定义一个方法: def getname(self ...