题目链接

题意 : 一个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(模拟)的更多相关文章

  1. POJ 1027:The Same Game 较(chao)为(ji)复(ma)杂(fan)的模拟

    The Same Game Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5168   Accepted: 1944 Des ...

  2. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  3. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

  4. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  5. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  6. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  7. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  8. POJ 3672 Long Distance Racing (模拟)

    题意:给定一串字符,u表示是上坡,d表示下坡,f表示平坦的,每个有不同的花费时间,问你从开始走,最远能走到. 析:直接模拟就好了,没什么可说的,就是记下时间时要记双倍的,因为要返回来的. 代码如下: ...

  9. poj 1696 Space Ant(模拟+叉积)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3840   Accepted: 2397 Descrip ...

随机推荐

  1. RMAN - "丢失控制文件的恢复"

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  2. centos6 自启动任务

    tag: init upstart centos6.x 自启动 initctl event CentOS6开始转用Upstart代替以往的init.d/rcX.d的线性启动方式.upstart的概念就 ...

  3. iOS学习之UI自定义cell

    一.自定义Cell 为什么需要自定义cell:系统提供的cell满足不了复杂的样式,因此:自定义Cell和自定义视图一样,自己创建一种符合我们需求的Cell并使用这个Cell.如下图所示的这些Cell ...

  4. 基于NPOI导出Excel

    在上一篇文章[关于大数据的查询与导出]中,提到了使用NPOI组件导出Excel,本想上次一起分享给大家,无奈最近比较忙,今天抽空整理了下,分享出来. 预置填充模板,并且需要支持公式计算; 可导入图片; ...

  5. How to Call a synchronize function asynchronizly in C#

    How to call a function asynchronizly in C# # Page1- Delegate.begininvoke, endinvoke BeginInvoke and ...

  6. Python实现CART(基尼指数)

    Python实现CART(基尼指数) 运行环境 Pyhton3 treePlotter模块(画图所需,不画图可不必) matplotlib(如果使用上面的模块必须) 计算过程 st=>start ...

  7. Daily Scrum2

    今天我们小组开会内容分为以下部分: part 1: 之前的失败教训: part 2: 针对Anti-spam and anti-abuse module模块的任务分工: part 3: 之后小组成员必 ...

  8. “我爱淘”冲刺阶段Scrum站立会议3

    完成任务: 将搜索框的界面已经实现以及部署到整个框架中. 计划任务: 实现搜索功能,通过数据库的链接,实现用户可以查到自己需要的书籍的信息. 遇到问题: 1.数据库的操作,怎么实现查询功能: 2.Ac ...

  9. Bootstrap入门二:响应式页面布局

    Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列.它包含了易于使用的预定义类,还有强大的mixin 用于生成更具 ...

  10. 19、android面试题整理(自己给自己充充电吧)

    (转载,出处丢失,请原作者原谅,如有意见,私信我我会尽快删除本文) JAVA 1.GC是什么? 为什么要有GC?GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问 ...