QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#220585 | #7184. Transport Pluses | BILLION_mengyi | ML | 4ms | 35596kb | C++20 | 3.1kb | 2023-10-20 16:01:04 | 2023-10-20 16:01:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PLL;
const int N=1000010;
ll n,t;
ll xh,yh;
ll xe,ye;
ll x[N],y[N];
ll idx;
ll id[110][110];
double dist[N];
PLL p[11000];
struct Edge
{
ll to;
double w;
ll type;
};
struct Node
{
ll fa;
ll type;
}f[N];
struct ANS
{
ll to;
ll type;
};
vector<Edge> g[N];
map<PLL,ll> mp;
bool st[N];
double calc(ll x1,ll y1,ll x2,ll y2)
{
double x=fabs((double)x1-x2);
double y=fabs((double)y1-y2);
return sqrt(x*x+y*y);
}
void build(ll x1,ll y1,ll type,double w)
{
ll idd=id[y1][x1];
for(ll i=0;i<=100;i++)
{
if(i!=x1)
{
w=calc(x1,y1,i,y1);
Edge xx={id[y1][i],w,type};
g[idd].emplace_back(xx);
xx={idd,w,type};
g[id[y1][i]].emplace_back(xx);
}
}
for(ll i=0;i<=100;i++)
{
if(i!=y1)
{
w=calc(x1,y1,x1,i);
Edge xx={id[i][x1],w,type};
g[idd].emplace_back(xx);
xx={idd,w,type};
g[id[i][x1]].emplace_back(xx);
}
}
}
void build2(ll x1,ll y1,ll type,double w)
{
for(ll i=0;i<=100;i++)
{
ll idd=id[y1][i];
for(ll j=0;j<=100;j++)
{
ll idd2=id[y1][j];
if(idd==idd2) continue;
Edge xx={idd2,w,type};
g[idd].emplace_back(xx);
}
for(ll j=0;j<=100;j++)
{
ll idd2=id[j][x1];
if(idd==idd2) continue;
Edge xx={idd2,w,type};
g[idd].emplace_back(xx);
}
}
for(ll i=0;i<=100;i++)
{
ll idd=id[i][x1];
for(ll j=0;j<=100;j++)
{
ll idd2=id[y1][j];
if(idd==idd2) continue;
Edge xx={idd2,w,type};
g[idd].emplace_back(xx);
}
for(ll j=0;j<=100;j++)
{
ll idd2=id[j][x1];
if(idd==idd2) continue;
Edge xx={idd2,w,type};
g[idd].emplace_back(xx);
}
}
}
void dijkstra(ll start)
{
for(ll i=0;i<=10000;i++)
{
dist[i]=1000000007;
}
priority_queue<PLL,vector<PLL>,greater<PLL>> heap;
dist[start]=0;
heap.push({0,start});
while(heap.size())
{
ll u=heap.top().second;
double dis=heap.top().first;
heap.pop();
if(u==id[2][1])
{
ll wwwww=0;
}
if(st[u]) continue;
st[u]=true;
for(auto h:g[u])
{
ll j=h.to;
ll w=h.w;
ll type=h.type;
if(dist[j]>dis+w)
{
f[j]={u,type};
dist[j]=dis+w;
if(!st[j])
{
heap.push({dist[j],j});
}
}
}
}
}
void solve()
{
cin>>n>>t;
cin>>xh>>yh;
cin>>xe>>ye;
ll start=id[yh][xh];
ll endd=id[ye][xe];
build(xh,yh,0,0);
build(xe,ye,0,0);
double ww=calc(xh,yh,xe,ye);
for(ll i=1;i<=n;i++)
{
cin>>x[i]>>y[i];
build2(x[i],y[i],i,t);
}
dijkstra(start);
if(dist[endd]<ww)
{
printf("%.6lf\n",dist[endd]);
}
else
{
cout<<ww<<"\n";
cout<<"1\n";
cout<<0<<" "<<xe<<" "<<ye<<"\n";
return ;
}
vector<ANS> ans;
ll now=endd;
while(now!=start)
{
ans.push_back({now,f[now].type});
now=f[now].fa;
}
cout<<ans.size()<<"\n";
reverse(ans.begin(),ans.end());
for(auto h:ans)
{
cout<<h.type<<" "<<p[h.to].first<<" "<<p[h.to].second<<"\n";
}
}
int main()
{
for(ll i=0;i<=100;i++)
{
for(ll j=0;j<=100;j++)
{
id[i][j]=++idx;
p[idx]={j,i};
}
}
ll T=1;
while(T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 34408kb
input:
1 2 1 1 5 3 6 2
output:
4.000000 3 0 1 2 1 5 2 0 5 3
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 35596kb
input:
2 1 1 1 6 1 1 3 6 3
output:
2.000000 2 1 0 3 2 6 1
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 30620kb
input:
0 0 1 1 1 1
output:
0 1 0 1 1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 30960kb
input:
0 0 100 100 0 0
output:
141.421 1 0 0 0
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 33504kb
input:
1 0 100 100 0 0 100 100
output:
100.000000 2 1 100 0 0 0 0
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 33736kb
input:
1 0 100 100 0 0 100 0
output:
0.000000 1 1 0 0
result:
ok correct
Test #7:
score: 0
Accepted
time: 4ms
memory: 33652kb
input:
1 0 100 100 0 0 0 100
output:
0.000000 1 1 0 0
result:
ok correct
Test #8:
score: 0
Accepted
time: 4ms
memory: 33556kb
input:
1 100 50 50 0 0 50 50
output:
70.7107 1 0 0 0
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 33608kb
input:
1 100 50 50 0 0 0 50
output:
70.7107 1 0 0 0
result:
ok correct
Test #10:
score: 0
Accepted
time: 3ms
memory: 33888kb
input:
1 100 50 50 0 0 51 51
output:
70.7107 1 0 0 0
result:
ok correct
Test #11:
score: 0
Accepted
time: 4ms
memory: 34128kb
input:
1 100 50 50 0 0 2 53
output:
70.7107 1 0 0 0
result:
ok correct
Test #12:
score: -100
Memory Limit Exceeded
input:
1 100 0 0 100 100 50 50