USACO 2.2 Preface Numbering
Preface Numbering
A certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain subset of decimal numbers. Here is the standard set:
I 1 L 50 M 1000
V 5 C 100
X 10 D 500
As many as three of the same marks that represent 10n may be placed consecutively to form other numbers:
- III is 3
- CCC is 300
Marks that have the value 5x10n are never used consecutively.
Generally (with the exception of the next rule), marks are connected together and written in descending order to form even more numbers:
- CCLXVIII = 100+100+50+10+5+1+1+1 = 268
Sometimes, a mark that represents 10^n is placed before a mark of one of the two next higher values (I before V or X; X before L or C; etc.). In this case, the value of the smaller mark is SUBTRACTED from the mark it precedes:
- IV = 4
- IX = 9
- XL = 40
This compound mark forms a unit and may not be combined to make another compound mark (e.g., IXL is wrong for 39; XXXIX is correct).
Compound marks like XD, IC, and XM are not legal, since the smaller mark is too much smaller than the larger one. For XD (wrong for 490), one would use CDXC; for IC (wrong for 99), one would use XCIX; for XM (wrong for 990), one would use CMXC. 90 is expressed XC and not LXL, since L followed by X connotes that successive marks are X or smaller (probably, anyway).
Given N (1 <= N < 3,500), the number of pages in the preface of a book, calculate and print the number of I's, V's, etc. (in order from lowest to highest) required to typeset all the page numbers (in Roman numerals) from 1 through N. Do not print letters that do not appear in the page numbers specified.
If N = 5, then the page numbers are: I, II, III, IV, V. The total number of I's is 7 and the total number of V's is 2.
PROGRAM NAME: preface
INPUT FORMAT
A single line containing the integer N.
SAMPLE INPUT (file preface.in)
5
OUTPUT FORMAT
The output lines specify, in ascending order of Roman numeral letters, the letter, a single space, and the number of times that letter appears on preface page numbers. Stop printing letter totals after printing the highest value letter used to form preface numbers in the specified set.
SAMPLE OUTPUT (file preface.out)
I 7
V 2
题目大意,不想说什么了,炒鸡无聊的题目,给你罗马数字的表示规律,问你从1到n出现的字母出现了几次,按照权值排序输出
思路,没什么思路,直接模拟
/*
ID:fffgrdc1
PROB:preface
LANG:C++
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char biao[][][]={"","I","II","III","IV","V","VI","VII","VIII","IX",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","M","MM","MMM"};
int cnt[];
int trback[]={,'I'-'A','V'-'A','X'-'A','L'-'A','C'-'A','D'-'A','M'-'A'};
int main()
{
freopen("preface.in","r",stdin);
freopen("preface.out","w",stdout);
int n;
memset(cnt,,sizeof(cnt));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int nn=i;
string ans="";
int bitt=;
while(nn)
{
int temp=nn%;
ans=biao[bitt][temp]+ans;
bitt++;
nn/=;
}
//cout<<ans<<endl;
int len=ans.length();
for(int j=;j<len;j++)
{
cnt[ans[j]-'A']++;
}
}
for(int i=;i<=;i++)
{
if(cnt[trback[i]])
printf("%c %d\n",trback[i]+'A',cnt[trback[i]]);
}
return ;
}
USACO 2.2 Preface Numbering的更多相关文章
- USACO Section2.2 Preface Numbering 解题报告 【icedream61】
preface解题报告----------------------------------------------------------------------------------------- ...
- 【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的每个十进制数 转换成相应的罗马数字 ...
- Preface Numbering
链接 分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可 /* PROB:preface ID:wanghan LANG:C++ */ #include "iostream&qu ...
- 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 (手推)
题目描述 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 最多3个同样的可以表示为 ...
- p1465 Preface Numbering
用这个函数转成罗马数字统计就行了. #include <iostream> #include <cstdio> #include <cmath> #include ...
随机推荐
- [hihocoder][Offer收割]编程练习赛48
折线中点 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...
- idea下的jsp开发中cannot resolve taglib with uri的解决方法
写jsp难免会用到<c:foreach>标签,于是我在idea上的jsp顶头写下了 <%@ taglib prefix="c" uri= 'http://java ...
- 第九课: - 导出到CSV / EXCEL / TXT
第 9 课 将数据从microdost sql数据库导出到cvs,excel和txt文件. In [1]: # Import libraries import pandas as pd import ...
- javascript中对象属性搜索原则
为什么通过对象就能访问到原型中的属性或者方法? 属性搜索原则: 1 首先会在对象本身查找有没有该属性,如果有直接返回 2 如果没有,此时就会在构造函数中查找通过this给对象添加的成员中有没有,如果有 ...
- The AJAX response: XML, HTML, or JSON?
shared from: http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html 1. 返回XML文档 对返回的XML ...
- 编码和解码(字符串与byte[]之间的转换)
资源来自互联网http://www.cnblogs.com/dabaopku/archive/2012/02/27/2370446.html 非常蛋疼的事情, google 和 baidu 在编码是分 ...
- SqlServer与MySql语法比较
1.复制表(包括表结构.表数据) SqlServer: Select * into user_copy from user MySql: CREATE TABLE user_copy LIKE use ...
- VTK资料收集
使用Qt Creator开发VTK 原文链接:http://blog.csdn.net/numit/article/details/10200507 VTK应用系列:非常强大!非常善良 05-VTK在 ...
- MFC多标签页对话框
原文链接(有修改):http://blog.sina.com.cn/s/blog_6a1cdb3f0101llcw.html 1.新建一个MFC工程 取名PageSheet,选择Dialog base ...
- 01--vim常用快捷键
Linux中vim编辑器的功能非常强大,许多常用快捷键用起来非常方便,这里将我学vim入门时学的一些常用的快捷键分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉 ...