算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 骰子上色Uva253

本文介绍了一种算法,用于判断两个六面体通过旋转是否能互相匹配颜色布局。输入为两组六面体的颜色字符串表示,输出为布尔值表明是否匹配。通过排序和比较相对面的颜色来简化匹配过程。

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1.

picture21

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138tex2html_wrap140

Input

The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)

Output

The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.

Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE
只要每个面以及它的相对的面两个色子都一样即可
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int c1(const void *a,const void *b)
{
    return strcmp((char *)a,(char *)b);
}

int main()
{
    char s[13],s1[7]={},s2[7]={},cmp1[3][3]={},cmp2[3][3]={};
    int i,j,k,sum=0;
    while(gets(s))
    {
    for(i=0;i<6;i++)
    {
        s1[i]=s[i];
    }
    for(i=6;i<12;i++)
    {
        s2[i-6]=s[i];
    }
    for(k=0,i=0,j=5;i<3;i++,j--,k++)
    {
        cmp1[k][0]=s1[i];
        cmp1[k][1]=s1[j];
    }
    for(k=0,i=0,j=5;i<3;i++,j--,k++)
    {
        cmp2[k][0]=s2[i];
        cmp2[k][1]=s2[j];
    }
    for(i=0;i<3;i++)
    {
        qsort(cmp1[i],2,sizeof(char),c1);
        qsort(cmp2[i],2,sizeof(char),c1);
    }

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(strcmp(cmp2[i],cmp1[j])==0&&strcmp(cmp1[j],"00")!=0)
            {
                strcpy(cmp2[i],"00");
                strcpy(cmp1[j],"00");
                sum++;
            }

        }
    }


    if(sum==3)
        printf("TRUE\n");
    else
        printf("FALSE\n");
        sum=0;
    }
}

内容概要:本文详细阐述了车载以太网通信栈中两个核心模块——以太网接口(EthIf)以太网驱动(Eth)的功能需求技术规范。重点介绍了EthIf在上下层协议间的数据转发、硬件抽象、VLAN支持、PDU配置、队列调度、睡眠管理及性能计数器等方面的设计要求;同时深入描述了Eth模块在硬件初始化、工作模式切换、时间戳支持、DMA传输、流量整形调度、帧抢占等底层驱动功能的技术实现要点。整体围绕车载高可靠性、低延迟、可配置性强的通信需求展开,体现了现代汽车电子架构对高性能网络通信的支持能力。; 适合人群:从事汽车电子、车载网络通信、ECU开发的工程师,尤其是熟悉AUTOSAR架构并希望深入了解以太网协议栈底层机制的研发人员;具备一定嵌入式系统和网络通信基础的技术人员。; 使用场景及目标:①用于设计和实现符合车规级要求的以太网通信栈;②理解EthIfEth在车载网络中的角色分工协作机制;③掌握中断/轮询模式、VLAN处理、时间同步、流量调度、帧抢占等关键技术在实际系统中的应用;④支持高实时性应用场景如自动驾驶、多传感器融合等的网络架构设计。; 阅读建议:建议结合AUTOSAR标准文档及相关硬件手册进行对照学习,重点关注模块接口定义状态机行为,结合实际项目需求进行配置验证,并注意软硬件协同设计中的时序资源管理问题。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值