Ural 1155 麻烦子 黑书P204

题目地址:http://acm.timus.ru/problem.aspx?space=1&num=1155


将A,B,C,D,E,F,G,H一次标记为0,1,2,3,4,5,6,7

相当于涂色问题,用红黑两种颜色去涂,相邻的不能同色,

所以0、2、5、7 相同颜色,   1、3、4、6相同颜色

相同颜色的都可以通过另一种颜色转移,所以当这两种颜色个数之和相等的时候就可以消失,否则不可能



代码如下:

#include<iostream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

typedef long long LL;
const int N=3000009;

int a[8];

void move(int x,int y,int t)
{//将x上面的移到y上面通过t,可以减的就减掉
    while(a[x])
    {
        if(a[t]==0)
        {
            a[t]++;a[y]++;
            printf("%c%c+\n",t+'A',y+'A');
        }
        a[t]--;
        a[x]--;
        printf("%c%c-\n",t+'A',x+'A');
    }
}

int main()
{
    int i,j,n;
    for(i=0;i<8;i++)
        scanf("%d",&a[i]);
    int s1=a[0]+a[2]+a[5]+a[7],s2=a[1]+a[3]+a[4]+a[6];
    if(s1!=s2)
    {
        printf("IMPOSSIBLE\n");
        return 0;
    }

    move(2,0,1);
    move(5,0,4);
    move(7,0,4);
    move(6,4,5);
    move(1,4,0);
    move(3,4,0);
    while(a[0]--)
        printf("AE-\n");

    return 0;
}


  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值