UVALive 6277 - Addictive Bubbles (模拟)

来源:互联网 发布:私募通数据库 编辑:程序博客网 时间:2024/06/08 02:20

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4288

题意:一个h*w的图,有c中颜色,每次会消去相邻的相同颜色的那几个块,给你每种颜色的数量,让求出这个图

思路:每次消相同,那么我们就把相同颜色的放在一起就可以了,可以利用图的S型的转弯赋值,类似于蛇形填数

ac代码:

#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1010000#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;int gcd(int a,int b){return b?gcd(b,a%b):a;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headint a[11][11];int color[11];int main(){    int h,w,c,i,j;    while(scanf("%d%d%d",&h,&w,&c)!=EOF)    {        for(i=1;i<=c;i++)            scanf("%d",&color[i]);        int x=1,y=1,dir=1;        for(i=1;i<=c;i++)        {            while(color[i])            {                a[x][y]=i;                color[i]--;                if(x>=1&&x<=h&&y+dir>=1&&y+dir<=w)                    y+=dir;                else                {                    dir=dir==1?-1:1;                    x++;                }            }        }        for(i=1;i<=h;i++)        {            for(j=1;j<=w;j++)                printf("%d",a[i][j]);            printf("\n");        }    }    return 0;}
0 0