POJ 1027 The Same Game(模拟)
题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluster,同时cluster含有至少两个球),每次选择cluster中包含同色球最多的进行消除,每次消除完之后,上边的要往下移填满空的地方,一列上的球移动之前与之后相对位置不变,如果有空列,右边的列往左移动,每一列相对位置不变 。
思路 : 模拟。。。。。。不停的递归。。。。。
////POJ 1027
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;
int tmp,ans,tot,sum,k,xx,yy;
//tmp:cluster中同色球的个数,ans:每次要消除的球的个数,tot:当前图中剩的总的有颜色的球,sum,分值,k:步数,xx,yy指的是要消除的cluster是从该点开始的
bool v[][];
string a[];
char ch;
int dx[] = {,,,-};
int dy[] = {,,-,};
void remov(int x,int y)//递归消除掉同色的
{
char c = a[x][y];
a[x][y] = '';
for (int i = ; i < ; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (xx >= && yy >= && xx < && yy < && a[xx][yy] == c)
remov(xx,yy);
}
}
void cluster(int x,int y)
{
tmp++;
v[x][y] = ;
for (int k = ; k < ; k++)
{
int xx = x + dx[k];
int yy = y + dy[k];
if (xx >= && yy >= && xx < && yy < && !v[xx][yy] && a[xx][yy]==a[x][y])
cluster(xx,yy);
}
}
int Find()
{
int maxx = ;
memset(v,,sizeof(v));
for (int j = ; j < ; j++)
for (int i = ; i < ; i++)
if (!v[i][j] && a[i][j]!='')
{
tmp = ;
cluster(i,j);
if (tmp > maxx)
{
maxx = tmp;
ch = a[xx = i][yy = j];
}
}
return maxx;
}
void fresh()
{
for (int j = ; j < ; j++)
{
int cnt = ;
for (int i = ; i < ; i++)
if (a[i][j] == '') cnt++;
for (int i = ; i < -cnt ; i++)
while (a[i][j]=='')//因为是倒着输入的,所以换不是往上换
{
int c = i;
while (c != )
{
swap(a[c][j],a[c+][j]);
c++;
}
}
}
int vis1[],tmpx = ;
memset(vis1,,sizeof(vis1));
for (int j = ; j < ; j++)//找空列
{
int cnt = ;
for (int i = ; i < ; i++)
if (a[i][j] == '') cnt++;
if (cnt == )
{
vis1[j] = ;
tmpx++;
}
}
for (int j = ; j < -tmpx ; j++)
while (vis1[j] == )
{
int c = j;
while (c != )
{
for (int i = ; i < ; i++)
swap(a[i][c],a[i][c+]);
swap(vis1[c],vis1[c+]);
c++;
}
}
}
int main()
{
int T ,casee = ;
scanf("%d",&T);
while(T--)
{
for (int i=; i>=; i--)
cin >> a[i];
printf("Game %d:\n\n",casee ++);
tot = ;
k = ;
sum = ;
while ()
{
ans = Find();
if (ans <= ) break;
printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n",
k++,xx+,yy+,ans,ch,(ans-)*(ans-));
tot -= ans;
sum += (ans-)*(ans-);
remov(xx,yy);
fresh();
}
if (tot == ) sum += ;
printf("Final score: %d, with %d balls remaining.\n\n",sum,tot);
}
return ;
}
POJ 1027 The Same Game(模拟)的更多相关文章
- POJ 1027:The Same Game 较(chao)为(ji)复(ma)杂(fan)的模拟
The Same Game Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5168 Accepted: 1944 Des ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- POJ 3672 Long Distance Racing (模拟)
题意:给定一串字符,u表示是上坡,d表示下坡,f表示平坦的,每个有不同的花费时间,问你从开始走,最远能走到. 析:直接模拟就好了,没什么可说的,就是记下时间时要记双倍的,因为要返回来的. 代码如下: ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
随机推荐
- Word2013死机的问题
Word2013用公式编辑器经常死机,网上介绍方法.试试看https://zhidao.baidu.com/question/937023473910649252.html1.启动word2013 2 ...
- iOS之走进精益编程01
Model类 .h #import <Foundation/Foundation.h> @interface Product : NSObject @property (nonatomic ...
- mysql substring_index
select * from tablename where substring_index(field1,'_',-1)=‘abc' #表中field1的值结构为123_abc
- shell 编程基础
1 创建shell脚本文件 要创建一个shell脚本文件,必须在第一行指定要使用的shell,其格式为: #! /bin/bash 接着加上该shell文件的注释,说明该脚本文件用来干什么,有谁创建, ...
- 深入浅出TCP/IP簇
TCP/IP是“transmission Control Protocol/Internet Protocol”的简写,中文译名为传输控制协议/互联网络协议.TCP/IP不是一个协议,而是一个协议簇的 ...
- 57.DDR3的系统时钟编译错误
错误:Xst:2033 - Port I of Input buffer ddr3_mig/memc3_infrastructure_inst/se_input_clk.u_ibufg_sys_clk ...
- 自定义debug信息
#ifdef DEBUG #define debug(fmt,args...) printk(fmt ,##args) #define debugX(level,fmt,args...) if ...
- jsp或Action获取请求参数中文乱码
普通情况下,中文字符会被自动转换成iso-8859-1的编码格式通过网络传输,而这种格式是没办法直接表示出我们认识的中文字符的,所以还要手动将他转换回之前的字符集. 一般在servlet或者actio ...
- URAL 1920 Titan Ruins: the Infinite Power of Magic
大意: 有一张N*N的网格,你每次可以走一步,每格只能走一次,有没有一种方法让走了L步后回到一个距原点1步远的格子? 没有输出Unsuitable device,否则输出Overwhelming p ...
- Curse of Dimensionality
Curse of Dimensionality Curse of Dimensionality refers to non-intuitive properties of data observed ...