hdu 2258 优先队列
Continuous Same Game (1)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 410 Accepted Submission(s): 143
LL was interested in this game at one time, but he found it is so difficult to find the optimal scheme. So he always play the game with a greedy strategy: choose the largest group to remove and if there are more than one largest group with equal number of blocks, choose the one which contains the most preceding block ( (x1,y1) is in front of (x2,y2) if and only if (x1<x2 || x1==x2 && y1<y2) ). Now, he want to know how many points he will get. Can you help him?
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std; int n,m,MAX;
char tom[][];
int a[][];
int to[][]={{,},{,},{,-},{-,}};
bool hash[][];
bool use[][];
struct node
{
friend bool operator< (node n1,node n2)
{
if(n1.val>n2.val)return false;//no return true;
else if(n1.val==n2.val)
{
if(n1.x<n2.x)return false;
else if(n1.x==n2.x && n1.y<n2.y) return false;
}
return true;
}
int x,y,val;
};
struct st
{
int x,y;
};
priority_queue<node>Q; int bfs(int x,int y,int num)
{
int i,cout=;
queue<st>S;
st t,cur;
t.x=x;
t.y=y;
hash[x][y]=true;
S.push(t); while(!S.empty())
{
cur=S.front();
S.pop();
for(i=;i<;i++)
{
t=cur;
t.x=t.x+to[i][];
t.y=t.y+to[i][];
if(t.x>=&&t.x<n &&t.y>=&&t.y<m && !hash[t.x][t.y] && a[t.x][t.y]==num){
hash[t.x][t.y]=true;
cout++;
S.push(t);
}
}
}
return cout;
}
void change(node &t)
{
int i,j,k;
int qq[][];
memset(qq,,sizeof(qq));
memset(hash,false,sizeof(hash));
k = bfs(t.x,t.y,a[t.x][t.y]);
for(i=;i<n;i++)
for(j=;j<m;j++)
if(hash[i][j]) a[i][j]=;
for(i=;i<m;i++){
for(j=n-,k=n-;j>=;j--)
if(a[j][i]) qq[k--][i] = a[j][i];
}
memset(a,,sizeof(a));
for(i=,k=;i<m;i++){
for(j=;j<n;j++) if(qq[j][i]!=)break;
if(j==n)continue;
for(j=n-;j>=;j--)
a[j][k]=qq[j][i];
k++;
}
}
void dfs(int now)
{
int i,j,val;
bool flag=false;
node t;
while(!Q.empty()){
Q.pop();
}
if(now>MAX) MAX = now;
memset(hash,false,sizeof(hash));
for(i=;i<n;i++){
for(j=;j<m;j++){
if(!hash[i][j] && a[i][j]!=)
{
val = bfs(i,j,a[i][j]);
if(val == ) continue;
t.x=i;
t.y=j;
t.val=val*(val-);
flag=true;
Q.push(t);
}
}
}
if(flag==false) return;
t=Q.top();
change(t);
dfs(now+t.val);
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)>)
{
for(i=;i<n;i++)
scanf("%s",tom[i]);
for(i=;i<n;i++)
for(j=;j<m;j++)
a[i][j]=tom[i][j]-'';
MAX=-;
dfs();
printf("%d\n",MAX);
}
return ;
}
hdu 2258 优先队列的更多相关文章
- hdu 5306 优先队列
用到优先队列 #include<iostream> #include<string> #include<algorithm> #include<cstdio& ...
- HDU 4006 优先队列
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- hdu 5818 (优先队列) Joint Stacks
题目:这里 题意: 两个类似于栈的列表,栈a和栈b,n个操作,push a x表示把数x放进a栈的栈底,pop b 表示将栈b的栈顶元素取出输出,并释放这个栈顶元素,merge a b表示把后面的那个 ...
- hdu 4302 优先队列
进一步学习了优先队列的用法 题意:一只小动物在直线上走,起始位置为零,之后会出现食物,动物要去距离自己最短的食物那,若两边的食物距离相等,则选择之前走的方向的食物 0 x,代表x的位置出现了食物,1代 ...
- hdu 4393 优先队列
用优先队列储存每个人的初始距离和编号,每轮求出最快的人,然后pop掉 一开始想遍历队列的,后来发现队列没办法遍历,汗-_-! 题意,给几个第一秒冲出的距离和以后速度,求每秒后最前面人的编号,求完后最前 ...
- HDU 1058 优先队列or堆
本来应当是一道优先队列或者堆的题 因为每个数都应该是已经得到的数*2 *3 *5 *7而得到的 但是 2*7 大于 3*2 这就必须保证每次取得都是没有拿过的最小的数 但是它主动降低难度在样例里卖了个 ...
- hdu 4544 优先队列+贪心
题意:最近,减肥失败的湫湫为发泄心中郁闷,在玩一个消灭免子的游戏.游戏规则很简单,用箭杀死免子即可.箭是一种消耗品,已知有M种不同类型的箭可以选择,并且每种箭都会对兔子造成伤害,对应的伤害值分别为Di ...
- HDU 5700 优先队列(或者multiset) 或 线段树
题目大意:有n个区间,求k个区间,使得这k个区间相交的区间内数字之和最大.数列的数字均>=0 优先队列思路: 按照左端点sort,然后枚举左端点,假设他被覆盖过k次,然后用优先队列来维护最右端即 ...
- hdu 1026(优先队列+路径输出)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
随机推荐
- C++builder 图像字符流的存储和加载
__fastcall TForm6::TForm6(TComponent* Owner) : TForm(Owner) { #if 1 //for debug AllocConsole(); Atta ...
- Regist
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\Current ...
- 记录把方法添加到 JavaScript 对象不明白的地方
<!DOCTYPE html> <html> <body> <script> function person(firstname,lastname,ag ...
- HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- mysql 导出过长的数字列时变科学计数法问题解决办法
--mysql 导出数据时, 数字类型的列如果位数过长,变为科学技术发问题 concat('\t',a.IDCARD_NO) 例子: select concat('\t',a.IDCA ...
- 夺命雷公狗---node.js---5net模块玩telnet通信(中)
我们理论知识太多还不如实战,我们来写一个可以通过telnet腾讯的小玩意玩玩: var net = require('net'); var ChatServer = net.createServer( ...
- PTPX中的clock tree与LP design
PTPX在加入CPF/UPF这样的文件后,可以分析multi-voltage,power-gating这样的设计. 针对某个power rail的cell,PTPX支持进行annotate. set_ ...
- linux时区的设置
到目前为止,个人的理解就是linux中设置时区就是修改配置文件 /etc/localtime 而通常的做法就是让这个文件作为符号链接,链接到 /usr/share/zoneinfo/ 中的某个特定的时 ...
- zw版【转发·台湾nvp系列例程】HALCON EquHistoImage(Delphi)
zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) (Delphi ...
- [fedora21]给fedora21安装fcitx输入法
如果已经安装了ibus,需要卸载ibus: sudo yum remove ibus; 安装fcitx: sudo yum install fcitx fcitx-pinyin fcitx-con ...