QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578300#9253. Prism Palacecuongson#WA 99ms9080kbC++174.4kb2024-09-20 18:04:502024-09-20 18:04:50

Judging History

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

  • [2024-09-20 18:04:50]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:9080kb
  • [2024-09-20 18:04:50]
  • 提交

answer

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

using point_t=long long;
// using point_t=long double;  //全局数据类型

constexpr point_t eps=1e-8;
constexpr point_t INF=numeric_limits<point_t>::max();
constexpr long double PI=3.1415926535897932384l;

// 点与向量
template<typename T> struct point
{
    T x,y;

    bool operator==(const point &a) const {return (abs(x-a.x)<=eps && abs(y-a.y)<=eps);}
    bool operator<(const point &a) const {if (abs(x-a.x)<=eps) return y<a.y-eps; return x<a.x-eps;}
    bool operator>(const point &a) const {return !(*this<a || *this==a);}
    point operator+(const point &a) const {return {x+a.x,y+a.y};}
    point operator-(const point &a) const {return {x-a.x,y-a.y};}
    point operator-() const {return {-x,-y};}
    point operator*(const T k) const {return {k*x,k*y};}
    point operator/(const T k) const {return {x/k,y/k};}
    T operator*(const point &a) const {return x*a.x+y*a.y;}  // 点积
    T operator^(const point &a) const {return x*a.y-y*a.x;}  // 叉积,注意优先级
    int toleft(const point &a) const {const auto t=(*this)^a; return (t>eps)-(t<-eps);}  // to-left 测试
    T len2() const {return (*this)*(*this);}  // 向量长度的平方
    T dis2(const point &a) const {return (a-(*this)).len2();}  // 两点距离的平方

    // 涉及浮点数
    long double len() const {return sqrtl(len2());}  // 向量长度
    long double dis(const point &a) const {return sqrtl(dis2(a));}  // 两点距离
    long double ang(const point &a) const {return acosl(max(-1.0l,min(1.0l,((*this)*a)/(len()*a.len()))));}  // 向量夹角
    point rot(const long double rad) const {return {x*cos(rad)-y*sin(rad),x*sin(rad)+y*cos(rad)};}  // 逆时针旋转(给定角度)
    point rot(const long double cosr,const long double sinr) const {return {x*cosr-y*sinr,x*sinr+y*cosr};}  // 逆时针旋转(给定角度的正弦与余弦)
};

using Point=point<point_t>;

// 直线
template<typename T> struct line
{
    point<T> p,v;  // p 为直线上一点,v 为方向向量

    bool operator==(const line &a) const {return v.toleft(a.v)==0 && v.toleft(p-a.p)==0;}
    int toleft(const point<T> &a) const {return v.toleft(a-p);}  // to-left 测试


    // 涉及浮点数
    point<T> inter(const line &a) const {return p+v*((a.v^(p-a.p))/(v^a.v));}  // 直线交点
    long double dis(const point<T> &a) const {return abs(v^(a-p))/v.len();}  // 点到直线距离
    point<T> proj(const point<T> &a) const {return p+v*((v*(a-p))/(v*v));}  // 点在直线上的投影
};

using Line=line<point_t>;

// 多边形
template<typename T> struct polygon
{
    vector<point<T>> p;  // 以逆时针顺序存储

    size_t nxt(const size_t i) const {return i==p.size()-1?0:i+1;}
    size_t pre(const size_t i) const {return i==0?p.size()-1:i-1;}
    // 多边形面积的两倍
    // 可用于判断点的存储顺序是顺时针或逆时针
    T area() const
    {
        T sum=0;
        for (size_t i=0;i<p.size();i++) sum+=p[i]^p[nxt(i)];
        return sum;
    }

    // 多边形的周长
    long double circ() const
    {
        long double sum=0;
        for (size_t i=0;i<p.size();i++) sum+=p[i].dis(p[nxt(i)]);
        return sum;
    }
};

using Polygon=polygon<point_t>;

signed main()
{
    int n;
    cin>>n;

    if(n==3)
    {
        cout<<1;
        return 0;
    }

    Polygon poly;

    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        poly.p.push_back({x,y});
    }

    if(poly.area()<0)reverse(poly.p.begin(),poly.p.end());

    int mp1,mp2;
    int maxlen=0;
    double ans=0;
    for(int i=0;i<n;i++)
    {
        int nxti=poly.nxt(i);
        int len=poly.p[nxti].dis2(poly.p[i]);
        if(len>=maxlen)
        {
            if(len>maxlen)ans=0;
            maxlen=len;
            mp1=i;
            mp2=nxti;

            Point p0,p1,p2;
            p0=poly.p[mp2]-poly.p[mp1];
            p1=poly.p[poly.pre(mp1)]-poly.p[mp1];
            p2=poly.p[mp2]-poly.p[poly.nxt(mp2)];

            if( p0*p1 >= 0 && p0*p2 >= 0 && !(p0*p1 == 0 && p0*p2 == 0) )
            {
                p2=-p2;
                double r=acos(p1*p2*1.0/p1.len()/p2.len());
                r=r/PI;
                ans+=r;
            }

        }

    }
    if(ans<=eps)cout<<0;
    else cout<<fixed<<setprecision(15)<<ans;
    return 0;

}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

input:

3
0 0
1 0
0 1

output:

1

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #2:

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

input:

4
0 0
0 1
1 1
1 0

output:

0

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #3:

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

input:

4
0 0
0 3
1 2
1 1

output:

0.500000000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #4:

score: -100
Wrong Answer
time: 99ms
memory: 9080kb

input:

199996
719157942 80035870
719158808 80033199
719160795 80027070
719162868 80020675
719165635 80012139
719166422 80009711
719166927 80008153
719168388 80003645
719168539 80003179
719168806 80002355
719168864 80002176
719169119 80001389
719171067 79995376
719173806 79986921
719175195 79982633
71917686...

output:

0

result:

wrong answer 1st numbers differ - expected: '0.0000777', found: '0.0000000', error = '0.0000777'