zoukankan      html  css  js  c++  java
  • 牛客小白月赛41 小红的375

    题目链接

    直接判断一个数是不是375的倍数很难,但是判断一个数是不是3000(注意3000=375 \(\times\) 8)的倍数却很简单

    我们能想到任何一个是375的倍数的数都能表示成n \(\times\) 3000+m \(\times\) 375(m<=7)的形式

    然后直接枚举m就好了。

    #include<iostream>
    #include<cstring>
    #include<string>
    using namespace std;
    int len;
    int tong[13];
    char s[300010];
    int pan(int a,int b,int c,int d)
    {
    	tong[b]--;tong[c]--;tong[d]--;
    	for(int i=0;i<=9;++i)
    		if(tong[i]<0)
    		{
    			tong[b]++;tong[c]++;tong[d]++;
    			return 0;
    		}
    		
    	int now=0,ok=0;
    	for(int i=1;i<=9;++i)
    	{
    		now+=tong[i]*i;
    		if(tong[i])ok=1;
    	}
    	
    	if((ok||tong[0]==0)&&now>=a&&now%3==a)
    	{
    		for(int i=9;i>=0;--i)
    			for(int j=1;j<=tong[i];++j)printf("%d",i);
    		printf("%d%d%d",b,c,d);
    		return 1;
    	}
    	else 
    	{
    		tong[b]++;tong[c]++;tong[d]++;
    		return 0;
    	}
    }
    int main()
    {
    	scanf("%s",s+1);len=strlen(s+1);
    	for(int i=1;i<=len;++i)++tong[s[i]-'0'];
    	if(pan(0,0,0,0))return 0;
    	if(pan(0,3,7,5))return 0;
    	if(pan(0,7,5,0))return 0;
    	if(pan(1,1,2,5))return 0;
    	if(pan(1,5,0,0))return 0;
    	if(pan(1,8,7,5))return 0;
    	if(pan(2,2,5,0))return 0;
    	if(pan(2,6,2,5))return 0;
    	cout<<"-1";
    	return 0;
    }
    
  • 相关阅读:
    文言文
    【我回来了】TO DO LIST
    AFO
    [DP]
    [CF1221F]Choose a Square
    关于博主(2)
    自我介绍( 并不?
    老年选手的复健之路
    CSP/NOIP 2019 游记
    CSP前模板复习
  • 原文地址:https://www.cnblogs.com/wljss/p/15655811.html
Copyright © 2011-2022 走看看