您的位置:首页 > 其它

UVALive 6621 Pocket Cube(暴力)

2016-07-30 23:15 323 查看
思路:将操作都打个表出来然后暴力就好了,一般遇到这种题我都是甩锅给队友...

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define INF 0x3f3f3f3f
#define esp 1e-9
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int l0[24]={1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8};
int d0[24]={20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23};
int m0[24]={0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23};
int ca[6][4]={0,1,2,3,4,5,10,11,6,7,12,13,8,9,14,15,16,17,18,19,20,21,22,23};
struct Node
{
int x[24];
}be;
int n;
void rl( Node &a)
{
int ta[24];
for(int i=0;i<24;++i) ta[i] = a.x[l0[i]];
for(int i=0;i<24;++i) a.x[i] = ta[i];
}
void rd(Node &a)
{
int ta[24];
for(int i=0;i<24;++i) ta[i] = a.x[d0[i]];
for(int i=0;i<24;++i) a.x[i] = ta[i];
}
void rm(Node &a)
{
int ta[24];
for(int i=0;i<24;++i) ta[i] = a.x[m0[i]];
for(int i=0;i<24;++i) a.x[i] = ta[i];
}
int cal(Node &a)
{
int ans = 0;
for(int i=0;i<6;++i)
{
int f=1;
for(int j=1;j<=3;++j) if(a.x[ca[i][j]]!=a.x[ca[i][j-1]]) f=0;
if(f) ans++;
}
return ans;
}
int solve()
{
queue<Node> q;
q.push(be);
int ans = cal(be);
while(!q.empty()&&n--)
{
int si = q.size();
while(si--)
{
Node t = q.front(); q.pop();

Node t1 = t;
rl(t1); ans = max(ans, cal(t1));
q.push(t1);
rl(t1); rl(t1); ans = max(ans, cal(t1));
q.push(t1);

t1 = t;
rd(t1); ans = max(ans, cal(t1));
q.push(t1);
rd(t1); rd(t1); ans = max(ans, cal(t1));
q.push(t1);

t1 = t;
rm(t1); ans = max(ans, cal(t1));
q.push(t1);
rm(t1); rm(t1); ans = max(ans, cal(t1));
q.push(t1);

if(ans==6) return ans;
}
}
return ans;
}
int main()
{
while(scanf("%d", &n)==1)
{
for(int i=0;i<24;++i) scanf("%d", &be.x[i]);
printf("%d\n", solve());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: