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 ...
随机推荐
- iterator和iterable的区别
相关博客: http://blog.csdn.net/lipengcn/article/details/51700153 Java中Iterable和Iterator的辨析 http ...
- 第6章 服务模式 Service Interface(服务接口)
Service Interface(服务接口) 上下文 您正在设计企业应用程序,并且需要能够通过网络使用其部分功能.此功能需要能够被各类系统使用,因此互操作性是设计的重要方面.除互操作性之外,可能还需 ...
- MySQL数据库的使用流程,代码解释+Hibernate连接数据库
数据库的使用流程: 1.注册驱动: 2.用DriverManager.getConnection方法获得连接对象con: A方法: 3.用连接对象的createStatement()方法,获得可以执 ...
- Win10 BackgroundTask
1.这里面详细的说明了后台任务的搭建 调用等 提示: 1.BackgroundTaskRegistration 里面有这两个事件 OnCompleted/Progress 主要用来UpdateUI 这 ...
- CGContext与上下文
上下文指的是场景拥有的资源或属性. 上下文的操作包含上下文的设置: 和上下文的引用. 上下文是一个结构体. 主要包含结构体的设置和使用.
- 修改XtraMessageBox的内容字体大小
修改XtraMessageBox的内容字体大小 public static DialogResult Show(UserLookAndFeel lookAndFeel, IWin32Window ow ...
- 04 Django-ORM多表操作(进阶)
一.创建模型 下面我们通过图书管理系统,来设计出每张表之间的对应关系. 通过上图关系,来定义一下我们的模型类. from django.db import models class Book(mo ...
- web service服务是查询QQ用户是否在线
使用php5开发客户端: <?php try { //$client = new SoapClient("HelloService.wsdl",array('encoding ...
- Vue学习之路第十六篇:车型列表的添加、删除与检索项目
又到了大家最喜欢的项目练习阶段,学以致用,今天我们要用前几篇的学习内容实现列表的添加与删除. 学前准备: ①:JavaScript中的splice(index,i)方法:从已知数组的index下标开始 ...
- npm run build 打包项目,图片等资源使用相对路径会出现路径错误的问题
在build下的utils.js中,3使用 ‘vue-style-loader’ 依赖的地方添加 publicPath: '../../' , 如图: