算法竞赛入门经典 习题 2-10 排列(permutation)
习题 2-10
用1,2,3。....,9组成3个三位数abc。def和ghi,每一个数字恰好使用一次,要求abc:def:ghi=1:2:3。输出全部解。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int abc, def, ghi;
int a[10], count = 0; memset(a, 0, sizeof(a));
// printf("n\n");
for(abc = 123; abc <= 329; abc++)
{
def = 2*abc;
ghi = 3*abc; a[abc/100] = a[abc/10%10] = a[abc%10] = 1;
a[def/100] = a[def/10%10] = a[def%10] = 1;
a[ghi/100] = a[ghi/10%10] = a[ghi%10] = 1;
int i;
for( i = 1; i <= 9; i++)
count += a[i]; if(count == 9) printf("%d %d %d\n", abc, def, ghi);
count = 0;
memset(a, 0, sizeof(a));
}
system("PAUSE");
return 0;
}
总结:1 将全部可能出现的数字作为一个一维数组的下标,最后推断之和是否为9,假设小于9,必有重合。反之每一个数字仅仅有一个
2 推断过后。count和数组要清零。
算法竞赛入门经典 习题 2-10 排列(permutation)的更多相关文章
- 算法竞赛入门经典 习题2-10 排列(permutation)
习题2-10 排列(permutation) 用1,2,3,-,9组成3个三位数 abc, def, 和ghi,每个数字恰好使用一次,要求 abc:def:ghi = 1:2:3.输出所有解.提示:不 ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- [刷题]算法竞赛入门经典 3-12/UVa11809
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa11809:Floating-Point Numbers 代码: //UVa11 ...
- [刷题]算法竞赛入门经典 3-10/UVa1587 3-11/UVa1588
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-10/UVa1587:Box 代码: //UVa1587 - Box #include&l ...
- [刷题]算法竞赛入门经典 3-7/UVa1368 3-8/UVa202 3-9/UVa10340
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa13 ...
- [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...
- [刷题]算法竞赛入门经典 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO(我也是在网上找到的pdf,但不记得是从哪里搜刮到的了,就重新上传了一遍) PS:第一次写博客分享我的代码,不知道我对c ...
- 算法竞赛入门经典训练指南——UVA 11300 preading the Wealth
A Communist regime is trying to redistribute wealth in a village. They have have decided to sit ever ...
随机推荐
- MERGE INTO USING用法
MERGE INTO [your table-name] [rename your table here] USING ( [write your query here] )[rename your ...
- 安卓app测试之Monkey日志分析
转:原文:https://blog.csdn.net/a136332462/article/details/76066909 一.一般测试结果分析-搜索关键字: 1.无响应问题可以在日志中搜索 “A ...
- CLISTCTRL2
回顾: 刚刚写完,因为是分期写的,所以最初想好好做一下的文章格式半途而废了~说的也许会有点啰嗦,但是所有的基础用到的技术细节应该都用到了. 如果还有什么疑问,请回复留言,我会尽力解答. 如果有错误,请 ...
- 禁止foreach循环使用remove/add----快速失败
阿里巴巴开发手册中有一条: 7[强制]不要在 foreach 循环里进行元素的 remove / add 操作. remove 元素请使用 Iterator 方式,如果并发操作,需要对 Iterato ...
- 新一代 Linux 文件系统 btrfs 简介
https://www.ibm.com/developerworks/cn/linux/l-cn-btrfs/ Btrfs 简介 文件系统似乎是内核中比较稳定的部分,多年来,人们一直使用 ext2/3 ...
- idea之快速查看类所在jar包
- oracle 内连接 左外连接 右外连接的用法,(+)符号用法
1. 内连接很简单 select A.*, B.* from A,B where A.id = B.id select A.*, B.* from A inner join B on A.id = B ...
- DemoKit编译过程
E:\Project_code\EAE\src_rev_24139_A95LYD\Project\DemoKit>make release Checking uITRON - DemoKit r ...
- Andrew and Chemistry(树的同构)
Andrew and Chemistry(树的同构) 题链 将一棵树转化为最小表示法,将此时的树哈希一下,同时用map进行标记,就可以判断树是否存在同构 #include <map> #i ...
- PAT 1129 Recommendation System
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...