090.约瑟夫问题

简介: 090.约瑟夫问题
#include<stdio.h>
void main()
{
    int x,y,z;
    clrscr();
    puts("****************************************************************");
    puts("*  This program is to solve Problem of Bridegroom and Bride.   *");
    puts("* The Problem is as follows: Someone goes to 3 couples lovers' *");
    puts("* wedding. The bridegrooms are A,B,C and the brides are X,Y,Z. *");
    puts("* He wants to know who marries who and asks them. A says he    *");
    puts("* will marry to X, X says her fiance is C, C says he will marry*");
    puts("* to Z. The man knows that they are all kidding. What they said*");
    puts("* is not true. So try to find who will marry to who?           *");
    puts("****************************************************************");
    puts(" >> The solutions are:");
    printf("---------------------------------------------\n");
    for(x=1;x<=3;x++)          /*穷举x的全部可能配偶*/
        for(y=1;y<=3;y++)      /*穷举y的全部可能配偶*/
            for(z=1;z<=3;z++)    /*穷举z的全部可能配偶*/
                if(x!=1&&x!=3&&z!=3&&x!=y&&x!=z&&y!=z)  /*判断配偶是否满足题意*/
                {
        printf(" X will marry to %c.\n",'A'+x-1);    /*打印判断结果*/
        printf(" Y will marry to %c.\n",'A'+y-1);
        printf(" Z will marry to %c.\n",'A'+z-1);
                }
    printf("---------------------------------------------\n");
    printf(" Press any key to quit...");
    getch();
}
相关文章
UVALive 3882 - And Then There Was One【约瑟夫问题】
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1883 题意:n个人围成一圈,第一次删第m个人,然后每数K个删一个人,求最后一个人的编号 分析:典型的约瑟夫问题,和杀人游戏差不多,杀人游戏描述如下: 推导过程: 首先,我们要对问题描述改一下,n个人编号为0,1,2,….,n-1,f[n]表示n个人组成的约瑟夫环按照规则后最后一个存活的编号。
1335 0
|
算法
每日一题之约瑟夫问题
大家好,我是泡泡,给大家带来每日一题的目的是为了更好的练习算法,我们的每日一题这个月进度是数据结构,让大家练到各种各样的数据结构题目,熟悉数据结构的增删改查,一年以后,蜕变成为一个不一样的自己!
97 0
PTA猴子选大王(约瑟夫环问题)
PTA猴子选大王(约瑟夫环问题)
147 1
猴子选大王-约瑟夫环
jobdu-1188:约瑟夫环-ac 猴子选大王,如此经典的问题  
1267 0
【线性表】洛谷P1996 约瑟夫问题
前言 本题来自洛谷P1996. 题目链接:约瑟夫问题 - 洛谷
103 0
|
5月前
|
机器学习/深度学习
约瑟夫环
【10月更文挑战第11天】
118 5
【9】约瑟夫环问题
题目:给定n个数编号从1~n形成一个环,每次删除环中的第m个数,求最后一个被删除的数。 方案一:把n个数构造成一个环形链表,每次遍历链表删除一个。
872 0
|
5月前
约瑟夫环问题
约瑟夫环
41 0