当前位置:网站首页>[diary of supplementary questions] [2022 Hangdian summer school 1] b-dragon Slayer
[diary of supplementary questions] [2022 Hangdian summer school 1] b-dragon Slayer
2022-07-24 02:24:00 【cls1277】
Pro
https://acm.hdu.edu.cn/showproblem.php?pid=7139
Sol
The idea is relatively simple , Made several mistakes in detail .
About coordinate addition 0.5 Treatment method : Maintain the upper, lower, left and right sides of each point , Thus, when searching, judge the situation of that edge point according to the direction of the previous point , namely Do not force the point in the center of the grid to the vertex of the grid , Instead, it judges whether the search can continue according to the four edges connected by the vertex .
The idea is to press directly , use 1 Indicates that the wall exists ,0 Does not exist , To ensure that we can go from the beginning to the end , seek 0 The minimum number of .
A mistake was made here , When enumerating the number of states from small to large , If you can find it, just break 了 , It's not . namely Decimal numbers representing states and 0 There is no monotonic relationship between the number of , Therefore, once the conditions are met, you can't directly break, But after cycling all the States , Yes 0 The answer is to take the minimum number of .
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
//const LL maxn = ;
LL n, m, K, xs, ys, xt, yt;
struct Node {
LL a, b, c, d; // u, d, l, r;
};
struct Map {
bool u, d, l, r;
} mp[20][20];
struct Que {
LL x, y; //1u, 2d, 3l, 4r
};
bool vis[20][20];
const int dx[4] = {
0, 0, 1, -1};
const int dy[4] = {
1, -1, 0, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
LL t; cin>>t;
while(t--) {
cin>>n>>m>>K;
vector<Node> e(K+1);
cin>>xs>>ys>>xt>>yt;
Fo(i,1,K) {
LL a, b, c, d; cin>>a>>b>>c>>d;
if(a>c) swap(a, c);
if(b>d) swap(b, d);
e[i] = {
a, b, c, d};
}
LL len = (1<<K)-1, ans = INT_MAX;
Fo(k,0,len) {
Fo(i,0,n) Fo(j,0,m) mp[i][j] = {
0, 0, 0, 0}, vis[i][j] = 0;
Fo(i,1,K) {
if(((k>>(i-1))&1)==0) continue;
if(e[i].a==e[i].c) {
Fo(j,e[i].b,e[i].d) {
if(j==e[i].b) mp[e[i].a][j].u = 1;
else if(j==e[i].d) mp[e[i].a][j].d = 1;
else mp[e[i].a][j].u = mp[e[i].a][j].d = 1;
}
} else {
Fo(j,e[i].a,e[i].c) {
if(j==e[i].a) mp[j][e[i].b].r = 1;
else if(j==e[i].c) mp[j][e[i].b].l = 1;
else mp[j][e[i].b].l = mp[j][e[i].b].r = 1;
}
}
}
queue<Que> q; q.push({
xs, ys});
vis[xs][ys] = 1; bool flag = 0;
while(!q.empty()) {
Que u = q.front(); q.pop();
if(u.x==xt&&u.y==yt) {
flag = 1;
break;
}
Fo(i,0,3) {
LL tx=u.x+dx[i], ty=u.y+dy[i];
if(tx<0||ty<0||tx>=n||ty>=m||vis[tx][ty]) continue;
if(i==0&&!mp[tx][ty].r) {
vis[tx][ty] = 1;
q.push({
tx, ty});
} else if(i==1&&!mp[u.x][u.y].r) {
vis[tx][ty] = 1;
q.push({
tx, ty});
} else if(i==2&&!mp[tx][ty].u) {
vis[tx][ty] = 1;
q.push({
tx, ty});
} else if(i==3&&!mp[u.x][u.y].u) {
vis[tx][ty] = 1;
q.push({
tx, ty});
}
}
}
if(flag) ans = min(ans, K-__builtin_popcount(k));
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Opensmile introduction and problems encountered during installation
- Redraw the button and make your own circular LED indicator
- 5年接触近百位老板,身为猎头的我,发现升职的秘密不过4个字
- Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
- POP3客户端代码的实现
- College degree want to 0 basic programming after looking for a job feasible?
- In depth understanding of the underlying framework of wechat applet (II) component system, exprser
- 【MySQL】字符集utf8mb4无法存储表情踩坑记录
- Async await details & Promise
- 图解数组和链表详细对比,性能测试
猜你喜欢

Combined with actual combat, analyze gb/t 28181 (II) -- equipment directory synchronization

奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5

我国科学家在高安全量子密钥分发网络方面取得新进展

Visual full link log tracking

Leetcode 70 climbing stairs, 199 right view of binary tree, 232 realizing queue with stack, 143 rearranging linked list

Wallys/DR4019S/IPQ4019/11ABGN/802.11AC/high power

暗黑系王者,低照度图像增强技术解析
![[jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for](/img/7b/95df873bfcad6b14c009d2681cf2f6.png)
[jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for

The difference between.Split (",", -1) and.Split (",")
![STM32 installation tutorial and j-link burning driver installation tutorial [the next day]](/img/09/def640c771f1b9effaaec3844d4cd3.png)
STM32 installation tutorial and j-link burning driver installation tutorial [the next day]
随机推荐
Halide:: generator instructions
输入cnpm -v出现cnpm : 无法加载文件 C:\Users\19457\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。
Reconnaître le Protocole de couche de transport - TCP / UDP
Diablo king, analysis of low illumination image enhancement technology
[重要通知]星球线上培训第三期来袭!讲解如何在QTYX上构建自己的量化策略!...
Deliver temperature with science and technology, vivo protects the beauty of biodiversity
Research on XMPP service (I)
【数据集】——flyingthings3d光流部分数据集下载
The difference between.Split (",", -1) and.Split (",")
奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5
BPG notes (III)
因果学习开源项目:从预测到决策!
One year after graduation, I gave up the internship opportunity and taught myself software testing at home. The internship of my classmates has just ended. I have become a 12K monthly salary testing e
Canvas drawing (mouse click to draw and lift to end)
Research and analysis of the third-party dependency library Ag grid
The communication principle between native components, applets and clients, and the operation principle of video, map, canvas, picker, etc
stb_ Image replaces other libraries
[untitled]
文心大模型扬起新“帆”,产业应用大潮已至
Beansearcher receives array parameters and logical deletion