【CF375C】Circling Round Treasures
Solution
一个有趣的事情:题目中有很大的篇幅在介绍如何判断一个位置在不在所围的多边形中
那么。。给了方法当然就是要用啊
首先是不能包含\('B'\),处理方式很简单直接把他当成一个值为\(-inf\)的宝藏即可,这样所有的object就全部可以看成一类了,不需要再额外考虑
注意到object的总数很少,考虑状压,记\(vis[x][y][st]\)表示当前在\((x,y)\)这个点,射线与路径的交点数量为奇数的object的状态为\(st\),这种局面是否可行,然后对应的开一个\(step[x][y][st]\)表示达到这种局面所需要的最少步数,这个时候。。最短路既视感?
反正\(n\)和\(m\)也不大,所以我们可以考虑跑一个最短路,最后枚举一下\(st\),然后用\((x,y)\)为起点位置的状态去更新一下答案就好了
现在的问题是,如何计算一步移动对object的射线的影响
注意到这个射线其实随便选就好了。。所以方便起见,我们可以钦定每个点只看往其左上方延伸的、角度很小很小很小的一条射线就好了(也可以是别的方向啦随意随意,不过角度很小这个比较重要),角度小这个有一个好处就是,因为角度很小所以只有当纵坐标改变的时候才有可能产生交点,然后其他的情况判断就十分简单了
mark:特殊值什么的是个好东西
mark:没有思路的时候。。可以尝试从描述里面找提示。。?
代码大概长这个样子
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=25,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1},ST=1<<8;
const int inf=1e4;
struct Rec{
int x,y,val;
}a[20];
struct Data{
int x,y,st;
Data(){}
Data(int x1,int y1,int st1){x=x1; y=y1; st=st1;}
};
queue<Data> q;
int vis[N][N][ST],step[N][N][ST],inq[N][N][ST];
char mp[N][N];
int n,m,t,stx,sty,cnt,ans;
int St(int x){return 1<<x-1;}
bool in(int st,int x){return st>>(x-1)&1;}
bool ok(int x,int y){
if (x<1||y<1||x>n||y>m) return false;
return mp[x][y]=='.'||mp[x][y]=='S';
}
bool check(int x,int y,int nwx,int nwy,int id){
if (x==nwx) return false;
if (x==a[id].x&&y<a[id].y) return nwx<x;
if (nwx==a[id].x&&nwy<a[id].y) return x<nwx;
return false;
}
void bfs(){
Data v,u;
int x,y,st,xx,yy,nw;
while (!q.empty()) q.pop();
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
for (int k=0;k<(1<<cnt);++k)
step[i][j][k]=inf,inq[i][j][k]=false;
q.push(Data(stx,sty,0)); inq[stx][sty][0]=true;
step[stx][sty][0]=0;
while (!q.empty()){
x=q.front().x; y=q.front().y; st=q.front().st; q.pop();
vis[x][y][st]=true;
for (int i=0;i<4;++i){
xx=x+dx[i]; yy=y+dy[i];
if (!ok(xx,yy)) continue;
nw=st;
for (int j=1;j<=cnt;++j)
if (check(x,y,xx,yy,j))
nw^=St(j);
if (step[xx][yy][nw]>step[x][y][st]+1){
step[xx][yy][nw]=step[x][y][st]+1;
if (!inq[xx][yy][nw])
q.push(Data(xx,yy,nw)),inq[xx][yy][nw]=true;
}
}
inq[x][y][st]=false;
}
}
void get_ans(){
int tmp;
for (int st=0;st<(1<<cnt);++st){
if (!vis[stx][sty][st]) continue;
tmp=0;
for (int i=1;i<=cnt;++i)
if (in(st,i))
tmp+=a[i].val;
ans=max(ans,tmp-step[stx][sty][st]);
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
#endif
scanf("%d%d\n",&n,&m);
t=0; cnt=0;
for (int i=1;i<=n;++i){
for (int j=1;j<=m;++j){
scanf("%c",&mp[i][j]);
if ('0'<=mp[i][j]&&mp[i][j]<='9'){
a[mp[i][j]-'0'].x=i,a[mp[i][j]-'0'].y=j;
t=max(t,mp[i][j]-'0');
++cnt;
}
else if (mp[i][j]=='S')
stx=i,sty=j;
}
scanf("\n");
}
for (int i=1;i<=t;++i) scanf("%d",&a[i].val);
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
if (mp[i][j]=='B')
a[++cnt].x=i,a[cnt].y=j,a[cnt].val=-inf;
bfs();
get_ans();
printf("%d\n",ans);
}
【CF375C】Circling Round Treasures的更多相关文章
- CF 375C Circling Round Treasures [DP(spfa) 状压 射线法]
C - Circling Round Treasures 题意: 在一个$n*m$的地图上,有一些障碍,还有a个宝箱和b个炸弹.你从(sx,sy)出发,走四连通的格子.你需要走一条闭合的路径,可以自交 ...
- Circling Round Treasures CodeForces - 375C
C. Circling Round Treasures time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- 【JAVA】Math.Round()函数常见问题“四舍5入”
java.lang.Math.Round()使用时候,处理方式整理,方便以后查找 /** * 测试函数 2014-01-10 */ public class TestMath { pu ...
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
- Codeforces 375C Circling Round Treasures - 最短路 - 射线法 - 位运算
You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure wit ...
- 【Codeforces】Codeforces Round #373 (Div. 2) -C
C. Efim and Strange Grade Efim just received his grade for the last test. He studies in a special sc ...
随机推荐
- PHP反序列化漏洞代码审计—学习资料
1.什么是序列化 A.PHP网站的定义: 所有php里面的值都可以使用函数serialize()来返回一个包含字节流的字符串来表示.unserialize()函数能够重新把字符串变回php原来的值. ...
- vs2017搭建linux c++开发环境
最近一直在阅读ovs的源码,看到用户态代码的时候,需要对用户态的代码进行调试,一开始想直接使用linux中的GDB进行调试,但是ovs的工程太过于复杂,从网上找了些文章,发现vs2017能够支持lin ...
- Seven super tips for successful selling on Amazon
Check for orders daily: To ship quickly you need to find out about orders promptly. We will e-mail y ...
- .NET 4.0 Tuple 元组
Tuple是.NET 4.0的新特性,主要功能是动态返回数据结构,也可以用做临时数据结构. 原来做一些功能时需要一个方法返回几个值,有两种方法: 1. 非常难看.难用的OUT参数: 2. 新写一个实体 ...
- ES6的新特性(12)——Set 和 Map 数据结构
Set 和 Map 数据结构 Set 基本用法 ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. co ...
- The Bits (思维+找规律)
Description Rudolf is on his way to the castle. Before getting into the castle, the security staff a ...
- Scrum立会报告+燃尽图(十月二十九日总第二十次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2288 项目地址:https://git.coding.net/zhang ...
- 团队项目成员与题目(本地地铁查询app)
团队名称:Daydreaming团队成员及其特点:张运涛:能快速与团队成员中的每一位进行合作,能全面考虑遇到的问题,善于总结积累.能较好的理解老师与其他人员的想法要求.刘瑞欣:做事果断,善于领导,有想 ...
- dcom初步窥探一
一.问题带入: 从delphi 5开始,有许多人都面临过这样的问题:com应用开发出来并且在本机上运行一切正常,但是一旦分发出去实施远程访问时,就无法正常运行了.我自己有段时间在看到“拒绝访问”错误提 ...
- struts2--文件上传类型3
拦截器栈在<package>标签内 <action>标签外配置 如上我们如果把它定义成默认拦截器的话就不需要在 <action>标签中引入,没有的话需要引入拦截器 ...