021-2022-INES A. Armor and Weapons Solution(玄学剪枝,限界)
Posted Codjjj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了021-2022-INES A. Armor and Weapons Solution(玄学剪枝,限界)相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h>
#include <unordered_set>
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
#define x first
#define y second
const int N = 2e5+10;
unordered_map<int,bool>ust;
int n,m,qy;
int cnt1=20,cnt2=20;//玄学剪枝
queue<pair<PII,int>>q;
int maxx[2*N],maxy[2*N];
int bfs()
int res=1e18;
q.push(1,1,0);
while(q.size())
auto now=q.front();
q.pop();
int x=now.x.x,y=now.x.y,sp=now.y;
if(sp>=res)break;
if(x<=maxx[sp]&&y<=maxy[sp])continue;
if(x>maxx[sp]&&y>maxy[sp])maxx[sp]=x,maxy[sp]=y;
if(x==n&&y==m)
res=min(res,sp);
break;
int add=0;
if(ust[x*N+y]==1)add=1;
if(x==n)
cnt1--;
if(cnt1>=0)
while(y<m)
sp++;
if(ust[x*N+y]==1)add=1;else add=0;
y+=n+add;
res=min(res,sp);
continue;
if(y==m)
cnt2--;
if(cnt2>=0)
while(x<n)
sp++;
if(ust[x*N+y]==1)add=1;else add=0;
x+=m+add;
res=min(res,sp);
continue;
q.push(min(x+y+add,n),y,sp+1);
q.push(x,min(x+y+add,m),sp+1);
return res;
signed main()
scanf("%lld%lld",&n,&m);
scanf("%lld",&qy);
while(qy--)
int a,b;
scanf("%lld%lld",&a,&b);
ust[a*N+b]=1;
printf("%lld",bfs());
以上是关于021-2022-INES A. Armor and Weapons Solution(玄学剪枝,限界)的主要内容,如果未能解决你的问题,请参考以下文章
计蒜客 ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem-数学公式题