惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
量子位
aimingoo的专栏
aimingoo的专栏
V
V2EX
Vercel News
Vercel News
B
Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
S
Secure Thoughts
U
Unit 42
博客园 - 叶小钗
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
Help Net Security
Help Net Security
S
Security Affairs
Microsoft Security Blog
Microsoft Security Blog
W
WeLiveSecurity
博客园 - Franky
Forbes - Security
Forbes - Security
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Schneier on Security
Schneier on Security
I
InfoQ
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
Last Week in AI
Last Week in AI
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CERT Recently Published Vulnerability Notes
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
SecWiki News
SecWiki News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
J
Java Code Geeks

博客园 - 空气

没有不可能的事情 迅景如梭,旧游似梦,烟水程何限 [转]一些web开发中常用的、做成cs文件的js代码 数类 MBTI职业性格测试 Which Programming Lanuguage Are You? 如何解释内存中的内容 好久没来了。。。 第七章: 封装 - 空气 - 博客园 C/C++中的内存管理 经典正则表达式 二叉树的显示 第六章: 字符串 测试-通过Word 2007发布Blog 第五章: 数组 第四章: 从 autoboxing 和 unboxing 认识对象 第三章: 语法入门 1. 让自己习惯C++ 0. 序
软件工厂的考试题目程序
空气 · 2006-12-17 · via 博客园 - 空气

#include <iostream>
using namespace std;

int mul1[5];       // 第一个乘数
int mul2;          // 第二个乘数
int result[5];     // 结果
bool used[10];     // 记录每个数字是否用过

/** 对乘数的每一位进行列举 **/
// digit 是位数: 个十百千分别是1234
// carry 是上一位的进位
void fun(int digit, int carry)
{
    
if (digit > 4)
    
{
        
if (carry > 0)
            
return;

        
/* 找到,输出结果 */
        
int i;
        
for (i = 4; i >= 1; i--)
            cout 
<< mul1[i];
        cout 
<< endl;
        cout 
<< "*  " << mul2 << endl;
        cout 
<< "----" << endl;
        
for (i = 4; i >= 1; i--)
            cout 
<< result[i];
        cout 
<< endl << endl;        
    }


    
int num;
    
int temp;
    
/* 枚举这一位所有的数字 */
    
for (int i = 1; i <= 9; i++)
    
{
        
/* 若数字用过则继续寻找 */
        
// 这里可以剪掉很多枝
        if (used[i])
            
continue;
        temp 
= i * mul2 + carry;
        num 
= temp % 10;
        
if (used[num] || num == 0 || i == num)
            
continue;

        
/* 记录 */
        mul1[digit] 
= i;
        result[digit] 
= num;

        
/* 继续 DFS 遍历 */
        used[i] 
= true;
        used[num] 
= true;
        fun(digit
+1, temp/10);
        used[i] 
= false;
        used[num] 
= false;
    }

}


int main()
{
    
for (mul2 = 2; mul2 <= 9; mul2++)
    
{
        used[mul2] 
= true;
        fun(
10);
        used[mul2] 
= false;
    }


    
return 0;
}


http://blog.sina.com.cn/u/4b09e6080100071n