zoukankan      html  css  js  c++  java
  • 题目(7)答案

    其实都很简单,最重要的是3重循环不能超过内存限制
    尽可能缩小时间复杂度

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    bool check(int aNum1, int aNum2, int aNum3)
    {
    	bool search[15] = {false};
    	/*aNum1 = (aNum1 * 1000 + aNum2) * 1000 + aNum3;
    	string str;
    	str = int2str(aNum1);
    	192000->192384000->192384576*/
    	while(aNum1 != 0)
    	{
    		search[aNum1 % 10] = true;
    		aNum1 /= 10;
    	}
    	while(aNum2 != 0)
    	{
    		search[aNum2 % 10] = true;
    		aNum2 /= 10;
    	}
    	while(aNum3 != 0)
    	{
    		search[aNum3 % 10] = true;
    		aNum3 /= 10;
    	}
    	for(int i = 1; i <= 9; i++)
    	{
    		if(search[i] == true){
    			continue;
    		}
    		else
    			return false;
    	}
    	return true;
    }
    
    int main()
    {
    	/*
    	192 384 576
    	1~9 分成3组 每组3位数
    	这3个数成1:2:3比例 
    	*/
    	bool c = false;
    	for(int i = 100; i <= 333; i++)
    	{
    		for(int j = 200; j <= 666; j += 2)
    		{
    			for(int x = 300; x <= 999; x += 3)
    			{
    				c = check(i, j, x);
    				if(c and i * 2 == j and i * 3 == x)
    					cout << i << " " << j << " " << x << endl;
    			}
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    c++类的知识点(1)
    并查集经典例题分析
    并查集
    bfs-迷宫
    出栈次序--数学归纳法--蓝桥
    九宫重排
    Tomcat详解
    寒假日记-第三天
    寒假日记-第二天(MySQL语句)
    Java学期总结
  • 原文地址:https://www.cnblogs.com/coding365/p/12872425.html
Copyright © 2011-2022 走看看