QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227307 | #4376. Dragon slayer | ucup-team1001 | AC ✓ | 470ms | 3792kb | C++14 | 1.7kb | 2023-10-27 11:21:50 | 2023-10-27 11:21:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=40;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
struct nod
{
int x,y;
}ns,nt;
struct node
{
int x1,y1,x2,y2;
}nd[maxn];
bool vis[maxn][maxn];
bool ok[maxn];
int g[maxn*2][maxn*2];
void build(int k,int m,int n)
{
memset(vis,0,sizeof(vis));
memset(g,0,sizeof(g));
for(int i=0;i<k;i++)
{
if(ok[i])
{
if(nd[i].x1==nd[i].x2)
for(int y=nd[i].y1;y<=nd[i].y2;y++)
g[nd[i].x1][y]=1;
else
for(int x=nd[i].x1;x<=nd[i].x2;x++)
g[x][nd[i].y1]=1;
}
}
}
bool bfs(int n,int m)
{
queue<nod> q;
q.push(ns);
while(!q.empty())
{
int x=q.front().x,y=q.front().y;
q.pop();
if(x<0||y<0||x>2*n||y>2*m||g[x][y])
continue;
if(nt.x==x&&nt.y==y)
return 1;
if(vis[x][y])
continue;
vis[x][y]=1;
for(int i=0;i<4;i++)
{
q.push((nod){x+dx[i],y+dy[i]});
}
}
return 0;
}
int dfs(int n,int m,int k,int cur,int cnt)
{
int ans=-1;
if(k==cur)
{
build(k,m,n);
if(bfs(n,m))
return cnt;
else
return -1;
}
ok[cur]=0;
ans=max(ans,dfs(n,m,k,cur+1,cnt));
ok[cur]=1;
ans=max(ans,dfs(n,m,k,cur+1,cnt+1));
return ans;
}
void solve()
{
int n,m,k;
cin>>n>>m>>k;
cin>>ns.x>>ns.y>>nt.x>>nt.y;
ns.x*=2;
ns.x+=1;
ns.y*=2;
ns.y+=1;
nt.x*=2;
nt.x+=1;
nt.y*=2;
nt.y+=1;
for(int i=0;i<k;i++){
cin>>nd[i].x1>>nd[i].y1>>nd[i].x2>>nd[i].y2;
nd[i].x1*=2;
nd[i].x2*=2;
nd[i].y1*=2;
nd[i].y2*=2;
if(nd[i].x1>nd[i].x2)
swap(nd[i].x1,nd[i].x2);
if(nd[i].y1>nd[i].y2)
swap(nd[i].y1,nd[i].y2);
}
cout<<k-dfs(n,m,k,0,0)<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 470ms
memory: 3792kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 5 3 5 1 4 1 0
result:
ok 10 lines