Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目
1 second
256 megabytes
standard input
standard output
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 11, 55, 1010and 5050 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 3535 and the number IXI — to 1212.
Pay attention to the difference to the traditional roman system — in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 1111, not 99.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly nn roman digits I, V, X, L.
The only line of the input file contains a single integer nn (1≤n≤1091≤n≤109) — the number of roman digits to use.
Output a single integer — the number of distinct integers which can be represented using nn roman digits exactly.
1
4
2
10
10
244
In the first sample there are exactly 44 integers which can be represented — I, V, X and L.
In the second sample it is possible to represent integers 22 (II), 66 (VI), 1010 (VV), 1111 (XI), 1515 (XV), 2020 (XX), 5151 (IL), 5555 (VL), 6060 (XL) and 100100 (LL).
打表找规律
下面为打表程序
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int maxn = 1e6 + ;
set<int>st;
int n,sum=;
int val[]={,,,};
void dfs(int x) {
if (x==n+){
st.insert(sum);
return ;
}
for (int i= ;i< ;i++){
sum+=val[i];
dfs(x+);
sum-=val[i];
}
}
int main() {
for (int i= ;i<= ;i++) {
n=i;
sum=;
st.clear();
dfs();
printf("%d ",st.size());
}
return ;
}
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5 + ;
int ans[]={,,,,,,,,,,,};
int main() {
LL n;
scanf("%lld",&n);
if (n<=) printf("%d\n",ans[n]);
else printf("%lld\n",+(n-)*);
return ;
}
Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目的更多相关文章
- Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律
题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...
- Codeforces Round #493 (Div 2) (A~E)
目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...
- Codeforces Round #493 (Div. 2)
C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1 要么把所有的 ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)
Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp
题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- Codeforces Round #589 (Div. 2) A. Distinct Digits
链接: https://codeforces.com/contest/1228/problem/A 题意: You have two integers l and r. Find an integer ...
- Codeforces Round #532(Div. 2) A.Roman and Browser
链接:https://codeforces.com/contest/1100/problem/A 题意: 给定n,k. 给定一串由正负1组成的数. 任选b,c = b + i*k(i为任意整数).将c ...
- Cutting Codeforces Round #493 (Div. 2)
Cutting There are a lot of things which could be cut — trees, paper, “the rope”. In this problem you ...
随机推荐
- window上小而美的软件(推荐度按排名)
window上小而美的软件,推荐度按排名 Notepad++ 更好用更强大的笔记本 QTranslate 本地翻译神器 7-zip 解压缩软件 Wox 程序/文件/快捷 神器 1! Everthing ...
- netty in action 笔记 二
netty的数据容器 网络数据的基本单位大多为字节,Java NIO 提供了ByteBuffer 作为它的字节容器,但使用起来过于复杂和繁琐.在Netty中, ByteBuffer 替代品是ByteB ...
- CMD Markdown basic & Math Cheatsheet
CMD Markdown basic & Math Cheatsheet I am using CMD Markdown both at work and for study.You can ...
- rsync+inotify实现实时同步,自动触发同步文件
本文参考来自:http://chocolee.blog.51cto.com/8158455/1400596 我的需求和他的略有不同,同时做了一下更改,如下: 需求:两台机器相互为主备,搭建相同的两个服 ...
- 欢迎来怼--第七次Scrum会议
一.小组信息 队名:欢迎来怼 小组成员: 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/19 17:05~17:17,总计12min. 地 ...
- unordered_map(hash_map)和map的比较
测试代码: #include <iostream> using namespace std; #include <string> #include <windows.h& ...
- 二叉树及其遍历方法---python实现
github:代码实现 本文算法均使用python3实现 1. 二叉树 1.1 二叉树的定义 二叉树是一种特殊的树,它具有以下特点: (1)树中每个节点最多只能有两棵树,即每个节点的度最多为2 ...
- 转 Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
转自:http://www.cnblogs.com/SilenceTom/p/6697484.html 调用接口遇到Response for preflight has invalid HTTP st ...
- 原生js实现自定义alert风格和实现
2018年6月29 最新更新 添加函数节流,解决多次点击问题,添加单例模式,提高代码性能. <!DOCTYPE html> <html lang="en"> ...
- WITH REPLACE 含义
RESTORE DATABASE db_CSharp from disk='backup.bak' WITH REPLACE WITH REPLACE后面是限定条件,with replace意思是替换 ...