hdu 4801模拟题

/*
模拟;
注意:实质上一次魔方的一半要变化
用c++超内存
用g++过了
*/
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
    int f0[4],f4[4],f6[4],f8[4],f16[4],f20[4];
    int step;
} s,next;
int fnow[10000][6];
int kk(int f[4])
{
    if(f[0]==f[1]&&f[1]==f[2]&&f[2]==f[3])
        return 1;
    return 0;
}
int comp(struct node ss)//计算有几个面是同色
{
    int sum=0;
    sum+=kk(ss.f0);
    sum+=kk(ss.f4);
    sum+=kk(ss.f6);
    sum+=kk(ss.f8);
    sum+=kk(ss.f16);
    sum+=kk(ss.f20);
    return sum;
}
void  clock(int f[4],int fd[4])//顺时针旋转
{
    f[0]=fd[2];
    f[2]=fd[3];
    f[3]=fd[1];
    f[1]=fd[0];
    return ;
}
void clockfan(int f[4],int fd[4])//逆时针旋转
{
    f[0]=fd[1];
    f[1]=fd[3];
    f[3]=fd[2];
    f[2]=fd[0];
    return ;
}
void Switch(struct node s,int k)//6种旋转方式
{
    if(k==0)
    {
        next.f0[0]=s.f20[0];
        next.f0[2]=s.f20[2];
        next.f6[0]=s.f0[0];
        next.f6[2]=s.f0[2];
        next.f16[0]=s.f6[0];
        next.f16[2]=s.f6[2];
        next.f20[0]=s.f16[0];
        next.f20[2]=s.f16[2];
        clock(next.f4,s.f4);//要变化
    }
    if(k==1)
    {
        next.f20[0]=s.f0[0];
        next.f20[2]=s.f0[2];
        next.f0[0]=s.f6[0];
        next.f0[2]=s.f6[2];
        next.f6[0]=s.f16[0];
        next.f6[2]=s.f16[2];
        next.f16[0]=s.f20[0];
        next.f16[2]=s.f20[2];
        clockfan(next.f4,s.f4);//要变化
    }
    if(k==2)
    {
        next.f4[0]=s.f6[0];
        next.f4[1]=s.f6[1];
        next.f20[2]=s.f4[1];
        next.f20[3]=s.f4[0];
        next.f8[0]=s.f20[3];
        next.f8[1]=s.f20[2];
        next.f6[0]=s.f8[0];
        next.f6[1]=s.f8[1];
        clock(next.f0,s.f0);
    }
    if(k==3)
    {
        next.f6[0]=s.f4[0];
        next.f6[1]=s.f4[1];
        next.f4[0]=s.f20[3];
        next.f4[1]=s.f20[2];
        next.f20[3]=s.f8[0];
        next.f20[2]=s.f8[1];
        next.f8[0]=s.f6[0];
        next.f8[1]=s.f6[1];
        clockfan(next.f0,s.f0);
    }
    if(k==4)
    {
        next.f0[2]=s.f8[0];
        next.f0[3]=s.f8[2];
        next.f4[1]=s.f0[3];
        next.f4[3]=s.f0[2];
        next.f16[0]=s.f4[1];
        next.f16[1]=s.f4[3];
        next.f8[0]=s.f16[1];
        next.f8[2]=s.f16[0];
        clockfan(next.f6,s.f6);
    }
    if(k==5)
    {
        next.f8[0]=s.f0[2];
        next.f8[2]=s.f0[3];
        next.f0[3]=s.f4[1];
        next.f0[2]=s.f4[3];
        next.f4[1]=s.f16[0];
        next.f4[3]=s.f16[1];
        next.f16[1]=s.f8[0];
        next.f16[0]=s.f8[2];
        clock(next.f6,s.f6);
    }
}
int n,len;
void chh(int &f,int fd[4])
{
     f=fd[3];
     f=f*6+fd[2];
     f=f*6+fd[1];
     f=f*6+fd[0];
    return ;
}
void fswitch(struct node s,int kf[6])
{
    chh(kf[0],s.f0);
    chh(kf[1],s.f4);
    chh(kf[2],s.f6);
    chh(kf[3],s.f8);
    chh(kf[4],s.f16);
    chh(kf[5],s.f20);
    return ;
}
void bfs(struct node s)
{
    int j,k,maxx;
    struct node cur;
    maxx=comp(s);
    s.step=0;
    len=0;
    queue<node>q;
    q.push(s);
    while(!q.empty())
    {
        cur=q.front();
        q.pop();
        if(cur.step>=n)continue;
        for(k=0; k<6; k++)
        {
            next=cur;
            Switch(cur,k);
            j=comp(next);
            next.step++;
            q.push(next);
            if(j>maxx)
                maxx=j;
                if(maxx==6)break;
        }
        if(maxx==6)break;
    }
    printf("%d\n",maxx);
    return ;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d%d%d%d",&s.f0[0],&s.f0[1],&s.f0[2],&s.f0[3]);
        scanf("%d%d%d%d",&s.f4[0],&s.f4[1],&s.f6[0],&s.f6[1]);
        scanf("%d%d%d%d",&s.f8[0],&s.f8[1],&s.f4[2],&s.f4[3]);
        scanf("%d%d%d%d",&s.f6[2],&s.f6[3],&s.f8[2],&s.f8[3]);
        scanf("%d%d%d%d",&s.f16[0],&s.f16[1],&s.f16[2],&s.f16[3]);
        scanf("%d%d%d%d",&s.f20[0],&s.f20[1],&s.f20[2],&s.f20[3]);
        bfs(s);
    }
    return 0;
}

时间: 2024-08-30 09:43:05

hdu 4801模拟题的相关文章

HDU 2158 模拟题

题目: 给定一个序列,有N个整数,数值范围为[0,N). 有M个询问,每次询问给定Q个整数,可能出现重复值. 要求找出一个最短区间,该区间要包含这Q个整数数值. 题解: 先便利一个整体的   L 和 R,   然后枚举L,  同时维护R,使得区间满足题目要求,更新最小区间, 直道不满足要求为止. 代码: #include<stdio.h> #include<string.h> #define N 100005 int a[N], find[N], mark[N]; int l, r

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.

HDU 4925 Apple Tree(模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种是种苹果树操作,第二种是施肥操作,种苹果树操作可以使得该块地 长出一个苹果,施肥操作可以使得与这块土地相邻的土地的苹果产量变为原来的两倍,问可以得到的最多的苹果数量是多少? 例如一个4*4的土地,用1表示在该土地上做第一种操作,0表示在该土地上做第二种操作,可以得到最多苹果的操作如下: 0 1 0

HDU 4941 Magical Forest _(:зゝ∠)_ 模拟题

模拟大法保平安_(:зゝ∠)_ #include <cstdio> #include <map> #include <set> #include <algorithm> using namespace std; const int N = 1; struct node{ int x, y, val; node(int a=0,int b=0,int c=0):x(a),y(b),val(c){} bool operator<(const node&am

hdu 4119 Isabella&#39;s Message 模拟题

Isabella's Message Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4119 Description Isabella and Steve are very good friends, and they often write letters to each other. They exchange funny experiences, talk ab

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<

HDU多校联合赛(1007 Magical Forest)模拟题

题目: Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magical fruits, These fruits can provide a lot of energy, Each fruit has its location(Xi, Yi) and the energy can be provided Ci. However, the forest wi