习题2-6  排序 permutation

用1,2,3……9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3。按照“abc def ghi”的格式输出所有解,每行一个解。提示:不必太动脑筋。

我的思路:

既然每个数字只能出现一次,那么就将1-9这九个数字出现的情况做记录,出现了的赋值为1,没有出现的为0。

然后分别对应着abc,def,ghi的百、十、个三位。

最后进行累加,如果累加器结果为9,那么说明每个数字出现了一次,则可以输出,否则不然。

#include "stdio.h"
int main()
{
for(int abc=;abc<=;abc++)//确定abc最小值和最大值
{//1-9出现的数字为1,没有出现的为0,累加起来,等于9则正确,否则错误
int s[]={}; //定义一个数组记录0~9出现的次数,并且循环前置零,
//防止上一轮出现的1在这一轮没有出现,影响最后累加,导致多加
s[abc/]=;//百位 a
s[abc/%]=;//十位 b
s[abc%]=;//个位 c int def=*abc;//令def为abc的2倍
s[def/]=;//百位 d
s[def/%]=;//十位 e
s[def%]=;//个位 f int ghi=*abc;//令ghi为abc的3倍
s[ghi/]=;//百位 g
s[ghi/%]=;//十位 h
s[ghi%]=;//个位 i int count=;//累加器
for(int i=;i<=;i++)//实现1-9的累加计数
count+=s[i];
if(count==)//如果1-9都出现了,则输出这些组合
printf("%d %d %d\n",abc,def,ghi);
}
return ;
}

排序 permutation的更多相关文章

  1. 字典排序permutation

    理论 C++ 中的next_permutation 一般作为正序全排列的使用规则,其实这个就是正序字典排序的实现. 比如我们要对 列表 [1,2,3]  做full permutation 一般使用递 ...

  2. pandas中的随机排序和抽样

    1.随机重排序 使用take()随机排序 如: df.take([54])   #采取索引为54的数据 可以借助np.random.permutation()函数随机排序 permutation()函 ...

  3. leetCode 31.Next Permutation (下一个字典序排序) 解题思路和方法

    Next Permutation  Implement next permutation, which rearranges numbers into the lexicographically ne ...

  4. CF798E. Mike and code of a permutation [拓扑排序 线段树]

    CF798E. Mike and code of a permutation 题意: 排列p,编码了一个序列a.对于每个i,找到第一个\(p_j > p_i\)并且未被标记的j,标记这个j并\( ...

  5. Coursera Algorithms week2 基础排序 练习测验: Permutation

    题目原文: Given two integer arrays of size n , design a subquadratic algorithm to determine whether one ...

  6. [LeetCode] 60. Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  8. Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  9. HDU 4917 Permutation(拓扑排序 + 状压DP + 组合数)

    题目链接 Permutation 题目大意:给出n,和m个关系,每个关系为ai必须排在bi的前面,求符合要求的n的全排列的个数. 数据规模为n <= 40,m <= 20. 直接状压DP空 ...

随机推荐

  1. [翻译] KVNProgress

    KVNProgress KVNProgress is a fully customizable progress HUD that can be full screen or not. KVNProg ...

  2. [翻译] MAThemeKit

    MAThemeKit https://github.com/mamaral/MAThemeKit MAThemeKit provides iOS developers the ability to c ...

  3. 乘风破浪:LeetCode真题_010_Regular Expression Matching

    乘风破浪:LeetCode真题_010_Regular Expression Matching 一.前言 关于正则表达式我们使用得非常多,但是如果让我们自己写一个,却是有非常大的困难的,我们可能想到状 ...

  4. 沉淀,再出发:XPath的理解和使用

    沉淀,再出发:XPath的理解和使用 一.前言   在很多查找的场合之下,我们需要使用正则表达式和其他的查找工具来进行内容的匹配和查找,特别是对于xml文件,我们可以使用xpath等工具来进行查找,通 ...

  5. [BZOJ 1924][Sdoi2010]所驼门王的宝藏

    1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1285  Solved: 574[Submit][Sta ...

  6. 美团2018年CodeM大赛-初赛B轮 B 配送(最短路)

    美团2018年CodeM大赛-初赛B轮 B 配送 题意 题解 对于每个任务,只要从上个任务的终点出发即可. 时间.地点很少,可以算出每个地点-时间的最小花费. 以题目描述的起点终点起始结束时间建图,很 ...

  7. wooyun内网渗透教学分享之内网信息探测和后渗透准备

    常规的,从web业务撕开口子url:bit.tcl.comgetshell很简单,phpcms的,一个Phpcms V9 uc api SQL的老洞直接getshell,拿到shell,权限很高,sy ...

  8. pushlet服务端推送——多播

    版权声明:本文为博主牟云飞原创文章.未经博主同意不得转载. https://blog.csdn.net/myfmyfmyfmyf/article/details/36364337 ---------- ...

  9. Kali-linux使用Nessus

    Nessus号称是世界上最流行的漏洞扫描程序,全世界有超过75000个组织在使用它.该工具提供完整的电脑漏洞扫描服务,并随时更新其漏洞数据库.Nessus不同于传统的漏洞扫描软件,Nessus可同时在 ...

  10. jquery mobile各类组件刷新方法

      1.Combobox or select dropdowns var myselect = $("#sCountry"); myselect[0].selectedIndex ...