QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645124#9472. Liaoning Ship’s VoyageAfterlife#AC ✓1ms3816kbC++202.9kb2024-10-16 16:58:532024-10-16 16:58:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 16:58:53]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3816kb
  • [2024-10-16 16:58:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

int n;

struct P{
    int x,y;
};

P operator -(const P &a,const P &b)
{
    return {a.x-b.x,a.y-b.y};
}

int det(const P &a,const P &b)
{
    return a.x*b.y-a.y*b.x;
}

int dot(const P &a,const P &b)
{
    return a.x*b.x+a.y*b.y;
}

bool inseg(const P &a,const P &b,const P &p)
{
    return det(b-a,p-a)==0&&dot(a-p,b-p)<=0;
}

bool in(const vector<P> &v,const P &a)
{
    for(int i=0;i<3;i++)
    {
        P u=v[(i+1)%3]-v[i];
        if(det(u,a-v[i])<=0)
            return 0;
    }
    return 1;
}

int sgn(int x)
{
    return x<0?-1:(x>0);
}

int ssinter(const P &a,const P &b,const P &c,const P &d)
{
    if(sgn(det(b-a,c-a))*sgn(det(b-a,d-a))==-1&&sgn(det(d-c,a-c))*sgn(det(d-c,b-c))==-1)
        return 1;
    return 0;
}

bool go(const vector<P> &v,const P &a,const P &b)
{
    if(in(v,a)||in(v,b))
        return 0;
    for(int i=0;i<3;i++)
        if(sgn(det(v[(i+1)%3]-v[i],b-a))==0&&sgn(det(v[(i+1)%3]-v[i],v[i]-a))==0)
            return 1;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
        {
            if(i==j)
                continue;
            if(inseg(v[i],v[(i+1)%3],a)&&inseg(v[j],v[(j+1)%3],b))
                return 0;
        }
    for(int i=0;i<3;i++)
        if(ssinter(v[i],v[(i+1)%3],a,b))
            return 0;
    for(int i=0;i<3;i++)
    {
        if(inseg(a,b,v[i])&&(inseg(v[(i+1)%3],v[(i+2)%3],a)||inseg(v[(i+1)%3],v[(i+2)%3],b)))
            return 0;
    }
    return 1;
}

int dx[]={1,1,0,-1,-1,-1,0,1},dy[]={0,-1,-1,-1,0,1,1,1};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin>>n)
    {
        vector<P> v(3);
        for(int i=0;i<3;i++)
        {
            double x,y;
            cin>>x>>y;
            v[i].x=round(x*100);
            v[i].y=round(y*100);
        }
        if(det(v[1]-v[0],v[2]-v[0])<0)
            swap(v[1],v[2]);
        vector<string> s(n,string(n,0));
        for(int i=0;i<n;i++)
        {
            string u;
            cin>>u;
            for(int j=0;j<n;j++)
                s[j][n-1-i]=u[j];
        }
        queue<pair<int,int> >q;
        vector<vector<int> >d(n,vector<int>(n,-1));
        d[0][0]=0;
        q.push({0,0});
        while(!q.empty())
        {
            auto [x,y]=q.front();
            q.pop();
            for(int e=0;e<8;e++)
            {
                int tx=x+dx[e],ty=y+dy[e];
                if(tx<0||tx>=n||ty<0||ty>=n)
                    continue;
                if(d[tx][ty]!=-1)
                    continue;
                if(s[tx][ty]=='#')
                    continue;
                if(!go(v,{x*100,y*100},{tx*100,ty*100}))
                    continue;
                d[tx][ty]=d[x][y]+1;
                q.push({tx,ty});
            }
        }
        cout<<d[n-1][n-1]<<"\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

3
0.5 1.5 1.5 1.5 1 0.5
.#.
...
..#
3
0.5 1.5 1.5 1.5 1 0.5
.#.
..#
..#

output:

3
-1

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3720kb

input:

3
0.5 0.5 1 -0.5 1.5 0.5
##.
##.
...
3
1 0.5 0.5 1 1.5 1
.#.
#.#
...
3
0.5 1.5 1.5 1.5 1 0.5
.#.
...
..#
3
0.5 1.5 1.5 1.5 1 0.5
.#.
..#
..#
10
4 6 5 6 5 4
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
10
4.5 4.2 4.2 6.2 4.8 6.2
..........

output:

-1
-1
3
-1
10
10
9
11
-1
11
-1
18
-1
3
-1

result:

ok 15 lines