C. Given Length and Sum of Digits...【1400贪心】

C. Given Length and Sum of Digits...【1400贪心】,第1张

C. Given Length and Sum of Digits...【1400 / 贪心】


https://codeforces.com/problemset/problem/489/C
就是贪心,小的是开头1从后往前尽量多点9
大的是开头尽量多的9.注意边界,很恶心。

#include
using namespace std;
int m,n;
int main(void)
{
    cin>>m>>n;
    if(n==0&&m==1) 
    {
    	cout<<"0 0";
    	return 0;
    }
	if( n==0&&m>1 || m*9 < n)
	{
		puts("-1 -1");
		return 0;
	}
	vectorA(m,0),B(m,0);
	A[0]=1;
	while(A[0]+9*(m-1)=1;i--)
	{
		if(temp>=9) A[i]=9,temp-=9;
		else A[i]=temp,temp=0;
	}
	for(int i=0;i					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4750585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-08
下一篇 2022-11-08

发表评论

登录后才能评论

评论列表(0条)

保存