1 条题解

  • 0
    @ 2024-3-28 19:25:11

    【2021年省赛B组】试题B:卡片

    题解

    • 一个简单的思路是对0到9定义一个次数数组,然后从1开始向后枚举,枚举到某个数时,便把这个数进行数位分解,然后对于所有的数位对应的次数数组都减去对应次数即可,直到某个数字的次数数字小于零,便是可以表示的最大数字,即为答案,利用代码算出最终答案为3181。

    提交代码

    #include<bits/stdc++.h>
    std::vector<int> divide(int x)
    {
    	std::vector<int> ans;
    	while(x)
    	{
    		ans.push_back(x % 10);
    		x /= 10;
    	}
    	return ans;	
    }
    
    void solve()
    {
    	std::vector<int> a(10);
    	for(int i = 0; i < 10; i++) a[i] = 2021;
    	int k = 1;
    	while(1)
    	{
    		auto b = divide(k);
    		for(auto x : b)
    		{
    			a[x]--;
    			
    			if(a[x] < 0)
    			{
    				std::cout << k - 1 << "\n";
    				return;
    			}
    		}
    		k++;
    	}
    }
    int main()
    {
    	std::ios::sync_with_stdio(false);
    	std::cin.tie(0);
    	int t = 1;
    	while(t--) solve();
    	return 0;
    }
    
    • 1

    信息

    ID
    977
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    79
    已通过
    35
    上传者