学军中学推理社2017届招新试题


迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int ab[12]= {0};
int tw()
{
    switch(ab[2])
    {
    case 1:
        if(ab[5]==3)return 0;
        break;
    case 2:
        if(ab[5]==4)return 0;
        break;
    case 3:
        if(ab[5]==1)return 0;
        break;
    case 4:
        if(ab[5]==2)return 0;
        break;
    }
    return 1;
}
int tr()
{
    switch(ab[3])
    {
    case 1:
        if(ab[6]!=1&&ab[2]!=1&&ab[4]!=1)return 0;
        break;
    case 2:
        if(ab[6]!=2&&ab[6]!=ab[2]&&ab[6]!=ab[4])return 0;
        break;
    case 3:
        if(ab[2]!=3&&ab[2]!=ab[6]&&ab[2]!=ab[4])return 0;
        break;
    case 4:
        if(ab[4]!=4&&ab[4]!=ab[2]&&ab[4]!=ab[6])return 0;
        break;
    }
    return 1;
}
int fo()
{
    switch(ab[4])
    {
    case 1:
        if(ab[1]==ab[5])return 0;
        break;
    case 2:
        if(ab[2]==ab[7])return 0;
        break;
    case 3:
        if(ab[1]==ab[9])return 0;
        break;
    case 4:
        if(ab[6]==ab[10])return 0;
        break;
    }
    return 1;
}
int fi()
{
    switch(ab[5])
    {
    case 1:
        if(ab[8]==1)return 0;
        break;
    case 2:
        if(ab[4]==2)return 0;
        break;
    case 3:
        if(ab[9]==3)return 0;
        break;
    case 4:
        if(ab[7]==4)return 0;
        break;
    }
    return 1;
}
int si()
{
    switch(ab[6])
    {
    case 1:
        if(ab[2]==ab[4]&&ab[8]==ab[2])return 0;
        break;
    case 2:
        if(ab[1]==ab[6]&&ab[1]==ab[8])return 0;
        break;
    case 3:
        if(ab[3]==ab[10]&&ab[3]==ab[8])return 0;
        break;
    case 4:
        if(ab[5]==ab[9]&&ab[8]==ab[5])return 0;
        break;
    }
    return 1;
}
int k[5];
int big(int n)
{
    for(int i=1; i<=4; i++)
        if(k[n]>k[i])return 0;
    return 1;
}
int se()
{
    switch(ab[7])
    {
    case 1:
        if(big(3))return 0;
        break;
    case 2:
        if(big(2))return 0;
        break;
    case 3:
        if(big(1))return 0;
        break;
    case 4:
        if(big(4))return 0;
        break;
    }
    return 1;
}
int te()
{
    int t=abs(k[4]-k[1]);
    switch(ab[10])
    {
    case 1:
        if(t==3)return 0;
        break;
    case 2:
        if(t==2)return 0;
        break;
    case 3:
        if(t==4)return 0;
        break;
    case 4:
        if(t==1)return 0;
        break;
    }
    return 1;
}
int ei()
{
    switch(ab[8])
    {
    case 1:
        if(abs(ab[7]-ab[1])!=1)return 0;
        break;
    case 2:
        if(abs(ab[5]-ab[1])!=1)return 0;
        break;
    case 3:
        if(abs(ab[2]-ab[1])!=1)return 0;
        break;
    case 4:
        if(abs(ab[10]-ab[1])!=1)return 0;
        break;
    }
    return 1;
}
int ni()
{
    int a=(ab[1]==ab[6]);
    switch(ab[9])
    {
    case 1:
        if((ab[6]==ab[5])!=a)return 0;
        break;
    case 2:
        if((ab[10]==ab[5])!=a)return 0;
        break;
    case 3:
        if((ab[2]==ab[5])!=a)return 0;
        break;
    case 4:
        if((ab[9]==ab[5])!=a)return 0;
        break;
    }
    return 1;
}
int panduan()
{
    memset(k,0,sizeof(k));
    if(tw())return 0;
    if(tr())return 0;
    if(fo())return 0;
    if(fi())return 0;
    if(si())return 0;
    if(ei())return 0;
    if(ni())return 0;
    for(int i=1; i<=10; i++)
        k[ab[i]]++;
    if(se())return 0;
    sort(k,k+5);
    if(te())return 0;
    return 1;
}
int digui(int i)
{
    if(i==11&&panduan())
        for(int a=1; a<=10; a++)
            printf("%d\t%c\n",a,64+ab[a]);
    else if(i<11)
        for(ab[i]=1; ab[i]<=4; ab[i]++)
            digui(i+1);
    return 0;
}
int main()
{
    printf("answer:\n");
    digui(1);
    return 0;
}

暴力枚举,简简单单偷笑

posted @ 2016-02-23 18:47  小坏蛋_千千  阅读(680)  评论(0编辑  收藏  举报