School idol project

Bad news! It is said that School of Software is going to be repealed because of low amount of new student. Many people says that TAs always give assignments which are too difficult to finish. Most high school graduates decide not to choose SS after hearing that.

To attract new students and save our school, some SSers decide to start a school idol project. They plan to set up an idol group which contains 9 members ( it seems that 9 is a popular size of school idol group ).

Now there are N students who wants to join the project, numbered from 0 to N-1. Please write a program to output all the possible combinations of the 9 school idols.

The input contains only one number N.

You should output at most 1000 lines, each line is one of the combinations. You should output them in alphabet order. In each line, numbers should be separated by space. There shouldn’t be any spaces at the end of a line. And there should be an empty line at the end of your output.

If C(N, 9) > 1000, output the first 1000 combinations.

Sample Input

10

Sample Output

0 1 2 3 4 5 6 7 8

0 1 2 3 4 5 6 7 9

0 1 2 3 4 5 6 8 9

0 1 2 3 4 5 7 8 9

0 1 2 3 4 6 7 8 9

0 1 2 3 5 6 7 8 9

0 1 2 4 5 6 7 8 9

0 1 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9

For all test cases, 9 <= N <= 10000

一开始,我想到的就是九重循环(hhhhh),但是还是打不出来,因为一直在纠结怎样退出循环的问题,以及怎样能使打印正常,然后看了看正确的九重,发现了return 0作用:

return 在main函数里面是程序退出的语句,当函数中遇到return 0;则会终止该函数

所以在大于1000时候,就可以通过标记退出mmain函数,然后循环的思路也就是这样,不要想得太复杂;;;;还有一个很重要的原来也不会,就是one,two……nine的范围,我一开始使他们都 < n,但是这样是错误的,而需要不断递减最小值,这点需要留意;;;

当然,并不提倡这种做法,如果需要排列100个,那就需要100重循环吗????掌握递归,听说是与深度优先搜索差不多,我再理解一下

我的
 1 #include<stdio.h>
 2 int main() {
 3     int n, a[10000], i, pan = 0;
 4     scanf("%d", &n);
 5     for (i = 0; i < n; i++) {
 6         a[i] = i;
 7     }
 8     int one, two, three, four, five, six, seven, eight, nine;
 9     for (one = 0; one < n - 8; one++) {
10         for (two = one + 1; two < n - 7; two++) {
11             for (three = two + 1; three < n - 6; three++) {
12                 for (four = three + 1; four < n - 5; four++) {
13                     for (five = four + 1; five < n - 4; five++) {
14                         for (six = five + 1; six < n - 3; six++) {
15                             for (seven = six + 1; seven < n - 2; seven++) {
16                             for (eight = seven + 1; eight < n - 1; eight++) {
17                                     for (nine = eight + 1; nine < n; nine++) {
18                                         printf("%d ", a[one]);
19                                         printf("%d ", a[two]);
20                                         printf("%d ", a[three]);
21                                         printf("%d ", a[four]);
22                                         printf("%d ", a[five]);
23                                         printf("%d ", a[six]);
24                                         printf("%d ", a[seven]);
25                                         printf("%d ", a[eight]);
26                                         printf("%d\n", a[nine]);
27                                         pan++;
28                                         if (pan >= 1000)
29                                             return 0;
30                                     }
31                                 }
32                             }
33                         }
34                     }
35                 }
36             }
37         }
38     }
39 }
标答
时间: 2024-08-25 12:24:43

School idol project的相关文章

Team Foundation Server 2013 with Update 3 Install LOG

[Info   @10:14:58.155] ====================================================================[Info   @10:14:58.163] Team Foundation Server Administration Log[Info   @10:14:58.175] Version  : 12.0.30723.0[Info   @10:14:58.175] DateTime : 10/03/2014 18:1

(转载)解决AndroidStudio导入项目在 Building gradle project info 一直卡住

源地址http://blog.csdn.net/yyh352091626/article/details/51490976 Android Studio导入项目的时候,一直卡在Building gradle project info这一步,主要原因还是因为被墙的结果.gradle官网虽然可以访问,但是速度连蜗牛都赶不上... 解决办法主要有两种,一是直接下载gradle离线包,二是修改项目的gradle-wrapper.properties里的gradle版本为自己电脑已有的版本. 离线包下载导

maven -- 问题解决(三)Java compiler level does not match the version of the installed Java project facet

问题: Java compiler level does not match the version of the installed Java project facet 解决方法如下: properties->Java Compiler,修改JDK版本,然后Apply

畅通project续HDU杭电1874【dijkstra算法 || SPFA】

http://acm.hdu.edu.cn/showproblem.php?pid=1874 Problem Description 某省自从实行了非常多年的畅通project计划后.最终修建了非常多路.只是路多了也不好,每次要从一个城镇到还有一个城镇时,都有很多种道路方案能够选择,而某些方案要比还有一些方案行走的距离要短非常多.这让行人非常困扰. 如今,已知起点和终点,请你计算出要从起点到终点.最短须要行走多少距离. Input 本题目包括多组数据.请处理到文件结束. 每组数据第一行包括两个正

log4j的1.2.15版本,在pom.xml中的顶层project报错错误: Failure to transfer javax.jms:jms:jar:1.1 from https://maven-repository.dev.java.net/nonav/repository......

在动态网站工程中,添加了Pom依赖,当添加log4j的1.2.15版本依赖时,在pom.xml中的顶层project报错错误: Failure to transfer javax.jms:jms:jar:1.1 from https://maven-repository.dev.java.net/nonav/repository......,如下图 这是因为 https://maven-repository.dev.java.net/nonav/repository 这个域名已经无法解析了. 而

Android studio project文件结构翻译

Android studio project文件结构翻译 个人翻译,用作备忘. 链接地址:https://developer.android.com/tools/projects/index.html#ApplicationModules Android Project Files Studio的项目文件和设置,设置的作用范围包含所有的module. 以以下的demo为例. .git:git版本控制的文件存放目录. .gradle:gradle执行一些编译所生成的目录 Idea: 由Intell

eclipse工程总是提示红叉,但是没有看到哪出错了!The project was not built due to &quot;Could not delete

最近在编译web project的时候,页面总是提示xx方法没有被定义为xx类.但是明明都是正确的. 而且在工程上有个红叉但是程序并没有看到哪有错误.如下图: 解决方法: 1.先打开problem窗口,才能看到意想不到的错误. Window-show view-other-找到problem.然后就会看到一条错误.如下: The project was not built due to "Could not delete '/build/com'.". Fix the problem,

项目无错误还报This project needs to migrate WTP metadata错

总得来说,项目出现错误:This project needs to migrate WTP metadata解决:右击该项目然后选择"验证",也就是Validate就可以解决,只不过位置不同. 简单的解决方法就是右击项目然后选择Validate,做完validate后错误就消失了. 但是我笔记本上myeclipse就是没有Validate选项,后来才发现,在项目右键选项myeclipse下有个run Validate,单击它之后,运行一会错误就消失了,好爽.

Project Management: 敏捷开发纵横谈

摘要:在IT界中,“敏捷”是一个很酷的词汇,“敏捷”的相关理论可谓铺天盖地.“敏捷”一词实质没有统一定义,各家有自家的说法,本教程将让你了解“敏捷”的来龙去脉,抓住“敏捷”本质,并能在工作中实践“敏捷”. 特别声明:如需转载此文,请给出指向本网站的连接,如下:作者:张传波摘自:http://www.umlonline.cn如不能按此要求,请不要转载此文. 大纲:“敏捷”陷阱为什么会有“敏捷”这个说法?极限编程敏捷开发RUP敏捷开发的实质是什么?如何才能敏捷起来? 正文: “敏捷”陷阱 小甲想到某