The 12th Zhejiang Provincial Collegiate Programming Contest - I Earthstone Keeper浙江省赛
题目:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5501
思路:DFS,用了递归就溢出,所以可能得用非递归的。把所有可能到达终点的可能路径都计算,最后比较找最佳。限制条件很多,要细打细算。很烦,不想改了再试,写了很久了
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <deque>
#include <stack>
#include <cstring>
#include <algorithm>
using namespace std;
char dun[][];
bool vis[][];
struct node
{
int x,y;
int peln,path; //惩罚/ 第几层
int s[]; //遇到的陷阱,26开始就是A
};
stack<node> que;
deque<node> anslist; int stax, stay;
int tarx, tary;
int n, m;
int fat, mins; void init(node &tmp) //初始化怪物标记s
{
for(int i=; i<; i++)
tmp.s[i]='';
}
bool tar(node tmp) //判断是否是目的地
{
if( tmp.x==tarx && tmp.y==tary )
return true;
else
return false;
}
bool cango(node tmp) //判断能不能走
{
if(tmp.x>=&&tmp.x<n&&tmp.y>=&&tmp.y<m )
{
if( dun[tmp.x][tmp.y]=='#' )
return false;
else
return true;
}
else
return false;
}
void adj_mon(node &tmp) //计算怪物惩罚
{
char c1='',c2='',c3='',c4='', c5=''; //走过可能干掉3只怪物 if( isupper( dun[tmp.x][tmp.y] ) ) //是怪物
{
c1=dun[tmp.x][tmp.y];
} node node1=tmp;
node1.x-=;
if( cango(node1)&&isupper( dun[tmp.x-][tmp.y] ) ) //是怪物
{
c2=dun[tmp.x-][tmp.y];
//cout<<"begin"<<endl;
} node1=tmp;
node1.x+=;
if( cango(node1)&&isupper( dun[tmp.x+][tmp.y] ) ) //是怪物
{
c3=dun[tmp.x+][tmp.y];
//cout<<"begin"<<endl;
} node1=tmp;
node1.y+=;
if( cango(node1)&&isupper( dun[tmp.x][tmp.y+] ) ) //是怪物
{
c3=dun[tmp.x][tmp.y+];
//cout<<"begin"<<endl;
} node1=tmp;
node1.y-=;
if( cango(node1)&&isupper( dun[tmp.x][tmp.y-] ) ) //是怪物
{
//cout<<"begin"<<endl;
c5=dun[tmp.x][tmp.y-];
} //*************************************
if(c1!=''&&tmp.s[ c1-'A'+ ]=='')
{
tmp.s[ c1-'A'+ ]=true;
tmp.peln+=( c1-'A'+ );
//cout<<"begin"<<endl;
} if(c2!=''&&tmp.s[ c2-'A'+ ]=='')
{
tmp.s[ c2-'A'+ ]=true;
tmp.peln+=( c2-'A'+ );
//cout<<"begin"<<endl;
} if(c3!=''&&tmp.s[ c3-'A'+ ]=='')
{
tmp.s[ c3-'A'+ ]=true;
tmp.peln+=(c3-'A'+);
//cout<<"begin"<<endl;
} if(c4!=''&&tmp.s[ c4-'A'+ ]=='')
{
tmp.s[ c4-'A'+ ]=true;
tmp.peln+=(c4-'A'+);
//cout<<"begin"<<endl;
} if(c5!=''&&tmp.s[ c5-'A'+ ]=='')
{
tmp.s[ c5-'A'+ ]=true;
tmp.peln+= c5-'A'+;
//cout<<"begin"<<endl;
} }
void trap(node &tmp) //计算陷阱惩罚
{
if( islower(dun[tmp.x][tmp.y]) ) //陷阱
tmp.peln += (dun[tmp.x][tmp.y] - 'a'+);
}
void cal_pel(node &tmp) //计算惩罚
{
trap(tmp);
adj_mon(tmp);
} int bfs(node tmp)
{
//判断四周有没有能进盏的
node node1=tmp;
node1.x-=;
if(cango(node1)) //合法
{ cal_pel(node1);
node1.path++;
if(tar(node1))
anslist.push_back(node1);
else if(vis[node1.x][node1.y]==false) //非目的
{
que.push(node1);
vis[node1.x][node1.y]=true;
bfs(node1);
que.pop();
vis[node1.x][node1.y]=false; } } node1=tmp;
node1.x+=;
if(cango(node1)) //合法
{
cal_pel(node1); node1.path++;
if(tar(node1))
anslist.push_back(node1);
else if(vis[node1.x][node1.y]==false) //非目的
{
que.push(node1);
vis[node1.x][node1.y]=true;
bfs(node1) ;
que.pop();
vis[node1.x][node1.y]=false;
}
} node1=tmp;
node1.y-=;
if(cango(node1)) //合法
{
cal_pel(node1); node1.path++;
if(tar(node1))
anslist.push_back(node1);
else if(vis[node1.x][node1.y]==false) //非目的
{
que.push(node1);
vis[node1.x][node1.y]=true;
bfs(node1) ;
que.pop();
vis[node1.x][node1.y]=false;
}
} node1=tmp;
node1.y+=;
if(cango(node1)) //合法
{
cal_pel(node1); node1.path++;
if(tar(node1))
anslist.push_back(node1);
else if(vis[node1.x][node1.y]==false) //非目的
{
que.push(node1);
vis[node1.x][node1.y]=true;
bfs(node1) ;
que.pop();
vis[node1.x][node1.y]=false;
} }
return ;
} int main()
{
//freopen("input.txt", "r", stdin);
int t;
cin>>t;
while(t--)
{
anslist.clear();
memset(dun, , sizeof(dun));
memset(vis, , sizeof(vis)); cin>>n>>m;
cin>>stax>>stay>>tarx>>tary;
stax-=;stay-=;tarx-=;tary-=; for(int i=; i<n; i++)
for(int j=; j<m; j++)
cin>>dun[i][j]; node tmp;
init(tmp);
tmp.x=stax; tmp.y=stay; tmp.peln=; tmp.path=; //起点
vis[tmp.x][tmp.y]=true;
que.push(tmp); //先进队
bfs(que.top()); deque<node>::iterator it=anslist.begin();
int min_path=;
int min_pel=;
for( ; it!=anslist.end(); it++)
{
//cout<<it->peln<<" "<<it->path<<endl; if(it->peln<=min_pel&&it->path<=min_path)
{
min_pel=it->peln;
min_path=it->path;
} }
cout<<min_pel<<" "<<min_path<<endl; } return ;
}
递归式的,seg错
The 12th Zhejiang Provincial Collegiate Programming Contest - I Earthstone Keeper浙江省赛的更多相关文章
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504 The 12th Zhejiang Provincial ...
- zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)
Floor Function Time Limit: 10 Seconds Memory Limit: 65536 KB a, b, c and d are all positive int ...
随机推荐
- Java Script 学习笔记 -- jQuery
一 jquery简介 1 jquery是什么 jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. jQuery是继prototyp ...
- Elasticsearch+Logstash+Kibana搭建分布式日志平台
一.前言 编译安装 1.ELK简介 下载相关安装包地址:https://www.elastic.co/cn/downloads ELK是Elasticsearch+Logstash+Kibana的简称 ...
- 《OD学hadoop》20160910某旅游网项目实战
一.event事件分析 叶子节点只计算一次 父节点的触发次数由子节点的数量节点 事件流:是由业务人员定义的一系列的具有前后顺序的事件构成的用户操作行为,至少包括两个事件以上. 目标:以事件流为单位,分 ...
- cogs 1685 魔法森林
/* 写了个傻逼二分套二分,真的傻逼了,我这tmd是在贪心呐,70分满满的人品 */ #include<iostream> #include<cstdio> #include& ...
- Cogs 1435. [USACO NOV]金发姑娘和N头牛
1435. [USACO NOV]金发姑娘和N头牛 ★★☆ 输入文件:milktemp.in 输出文件:milktemp.out 简单对比时间限制:1 s 内存限制:256 MB [题 ...
- POJ3274-Gold Balanced Lineup
题目链接:点击打开链接 Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16978 ...
- $each 遍历json字符串
$.each遍历json对象 查看一个简单的jQuery的例子来遍历一个JavaScript数组对象. var json = [ {"id":"1",&qu ...
- Helvetic Coding Contest 2016 online mirror C1
Description One particularly well-known fact about zombies is that they move and think terribly slow ...
- Django的用户认证组件,自定义分页
一.用户认证组件 1.auth模块 from django.conrtrib import auth django.contrib.auth中提供了许多方法,这里主要介绍其中的三个: 1)authen ...
- GUI的最终选择 Tkinter(五):Text用法
Text组件 绘制单行文本使用Label组件,多行选使用Listbox,输入框使用Entry,按钮使用Button组件,还有Radiobutton和Checkbutton组件用于提供单选或多选的情况, ...