题目链接

题意 : 一个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. memcached 高级机制(二)

    memcached删除机制 a) (1)有内存机制里说明了,这里会运用到LRU删除机制.我们知道,当我们在add或set一个值时,我们会设置这个值得期限.当某个值过期后,这个值并没有从内存中删除,我们 ...

  2. WIndows7 多版本

    Windows7 安装U盘 删除source\ei.cfg 以后开机安装会提示安装的版本

  3. Tutorial: Facebook analytics using Power BI Desktop

    In this tutorial you learn how to import and visualize data from Facebook. During the tutorial you'l ...

  4. libevent 定时器示例

    程序执行结果: 每隔2秒,触发一次定时器. (2)98行:evtimer_assign在event.h中定义如下: 再来看看event_assign函数: ev     要初始化的事件对象 base  ...

  5. VS中设置#define _CRT_SECURE_NO_WARNINGS的两种方式

    1.我们在编译老的用C语言的开源项目如lua源包的时候,可能因为一些老的.c文件使用了strcpy,scanf等不安全的函数,而报警告和错误,而导致无法编译通过. 2.此时我们有两种解决方案: a.在 ...

  6. 【转】eclipse技巧2

    谈谈eclipse使用技巧二 上节说道了怎么使用eclipse使您事半功倍.这节告诉您怎么用eclipse练成火眼金睛. ①借你一双火眼金睛让类的层次结构一目了然让你阅读代码如虎添翼 一个好的类的层次 ...

  7. JQuery常用实用的事件[较容易忽略的方法]

     JQuery常用实用的事件 注:由于JQuery片段较多就没有用插入代码文本插入,请见谅!JQuery 事件处理ready(fn)代码: $(document).ready(function(){ ...

  8. 21、HierarchyViewer使用记录

    1.是啥 HierachyViewer是一种能够方便开发人员了解activity中的布局信息的工具. 2.异常 HierachyViewer在未root过的设备或者低版本的设备是无法使用的 3.怎么办 ...

  9. OSGi运行环境下java反序列化问题的解决方式

    在OSGi环境下采用以下方式对其它bundle的类进行反序列化时,会出现ClassNotFoundException异常. ByteArrayInputStream bi = new ByteArra ...

  10. Window.document对象(1)

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...