zoukankan      html  css  js  c++  java
  • Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    The only line of the input file contains a single integer nn (1n1091≤n≤109) — the number of roman digits to use.

    Output

    Output a single integer — the number of distinct integers which can be represented using nn roman digits exactly.

    Examples
    input
    Copy
    1
    output
    Copy
    4
    input
    Copy
    2
    output
    Copy
    10
    input
    Copy
    10
    output
    Copy
    244
    Note

    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("******
    ")
    #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 + 10;
    set<int>st;
    int n,sum=0;
    int val[5]={1,5,10,50};
    void dfs(int x) {
        if (x==n+1){
            st.insert(sum);
            return ;
        }
        for (int i=0 ;i<4 ;i++){
            sum+=val[i];
            dfs(x+1);
            sum-=val[i];
        }
    }
    int main() {
        for (int i=1 ;i<=60 ;i++) {
            n=i;
            sum=0;
            st.clear();
            dfs(1);
            printf("%d ",st.size());
        }
        return 0;
    }
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <queue>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <set>
     7 #include <iostream>
     8 #include <map>
     9 #include <stack>
    10 #include <string>
    11 #include <vector>
    12 #define  pi acos(-1.0)
    13 #define  eps 1e-6
    14 #define  fi first
    15 #define  se second
    16 #define  lson l,m,rt<<1
    17 #define  rson m+1,r,rt<<1|1
    18 #define  bug         printf("******
    ")
    19 #define  mem(a,b)    memset(a,b,sizeof(a))
    20 #define  fuck(x)     cout<<"["<<x<<"]"<<endl
    21 #define  f(a)        a*a
    22 #define  sf(n)       scanf("%d", &n)
    23 #define  sff(a,b)    scanf("%d %d", &a, &b)
    24 #define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    25 #define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
    26 #define  pf          printf
    27 #define  FRE(i,a,b)  for(i = a; i <= b; i++)
    28 #define  FREE(i,a,b) for(i = a; i >= b; i--)
    29 #define  FRL(i,a,b)  for(i = a; i < b; i++)
    30 #define  FRLL(i,a,b) for(i = a; i > b; i--)
    31 #define  FIN         freopen("DATA.txt","r",stdin)
    32 #define  gcd(a,b)    __gcd(a,b)
    33 #define  lowbit(x)   x&-x
    34 #pragma  comment (linker,"/STACK:102400000,102400000")
    35 using namespace std;
    36 typedef long long LL;
    37 typedef unsigned long long ULL;
    38 const int maxn = 1e5 + 10;
    39 int ans[50]={0,4,10,20,35,56,83,116,155,198,244,292};
    40 int main() {
    41     LL n;
    42     scanf("%lld",&n);
    43     if (n<=11) printf("%d
    ",ans[n]);
    44     else  printf("%lld
    ",292+(n-11)*49);
    45     return  0;
    46 }
  • 相关阅读:
    Centos7安装nodejs(npm)
    Centos7安装docker
    在目标服务器Centos7上安装 GitLab Runner
    PC端,知乎在不想登录的情况下一打开就弹出登录框的无痛解决办法
    mac下webstrom卡顿快速解决办法
    解决项目中使用momentJS文件 体积过大的问题
    发布订阅模式及多种实现方式:
    「react进阶」react开发者的不得不知道的八条优化建议
    Gulp、Webpack 有什么区别
    react 源码解析(上)
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9445805.html
Copyright © 2011-2022 走看看