zoukankan      html  css  js  c++  java
  • [CF997B] Roman Digits

    [CF997B] Roman Digits - 组合,构造

    Description

    我们在研究罗马数字。罗马数字只有4个字符,I,V,X,L分别代表1,5,10,50 N 的罗马数字有多少种不同的值。(n le 10^9)

    Solution

    首先我们可以把 1,5,10,50 换成 0,4,9,49

    为了不重不漏,我们钦定,4 最多选 8 个,0 和 49 随便选

    那么 9 应该选多少个?

    (49 = 5 imes 9 + 1 imes 4 = 9 imes 9 - 2 imes 4)

    所以在不选 4 的时候,9 最多选 8 个(否则就可以换成另一种合法情况)

    在选 4 的时候,9 最多选 4 个(否则就可以换成另一种合法情况)

    因此,对于一个 n,我们暴力枚举选了 i 个 4,选了 j 个 9,那么此时 0 和 49 随便选,方案数贡献 n-i-j+1

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long 
    
    signed main()
    {
        ios::sync_with_stdio(false);
        int n;
        cin>>n;
        int ans=0;
        for(int i=0;i<=8;i++)
        {
            for(int j=0;j<=(i==0?8:4);j++)
            {
                ans+=max(0ll,n-i-j+1);
            }
        }
        cout<<ans<<endl;
    }
    
  • 相关阅读:
    POJ 2486
    奇怪的电梯
    穿越泥地(mud)
    救援行动(save)
    As Fast As Possible
    Connecting Universities
    They Are Everywhere
    Cells Not Under Attack
    吃饭
    花店橱窗(flower)
  • 原文地址:https://www.cnblogs.com/mollnn/p/14484723.html
Copyright © 2011-2022 走看看