QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245970#6676. Computational Geometryyiyiyi#AC ✓16ms4552kbC++204.0kb2023-11-10 14:53:222023-11-10 14:53:24

Judging History

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

  • [2023-11-10 14:53:24]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:4552kb
  • [2023-11-10 14:53:22]
  • 提交

answer

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<bitset>
#include<set> 
#define int long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define forE(i,x) for(int i=head[x];i;i=nxt[i])
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=1e6+5;
const int mod=998244353;
const int INF=1e9;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+(c-'0');
		c=getchar();
	}
	return x*f;
}

using point_t=int;  //全局数据类型,可修改为 long long 等

constexpr point_t eps=0;
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 测试 1left -1right 0on
    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 polygon
{
    vector<point<T>> p;  // 以逆时针顺序存储
};

using Polygon=polygon<point_t>;

//凸多边形
template<typename T> struct convex: polygon<T>
{

};

using Convex=convex<point_t>;

int T;

signed main()
{
    int T=read();
    while(T--)
    {
        int n=read(),k=read();
        Convex C;
        C.p.resize(n+5);
        rep(i,1,n) C.p[i]={read(),read()}; 
        int l=1,r=k,now=0,pos=k+1;
        int ans=0;
        now+=C.p[n]^C.p[1];
        rep(i,1,k-1) now+=C.p[i]^C.p[i+1];
        for(;l<=n;l++)
        {
            
            int nxt=(r==n)?1:r+1;
            int pre=(l==1)?n:l-1;
            now-=C.p[pre]^C.p[l];
            now+=C.p[r]^C.p[nxt];
            if(pos==nxt) pos=(pos==n)?1:pos+1;
            while(1)
            {
                Point v1=C.p[l]-C.p[pos],v2=C.p[nxt]-C.p[pos];
                int nxtpos = (pos==n)?1:pos+1;
                if(nxtpos==l) break;
                Point v3=C.p[l]-C.p[nxtpos],v4=C.p[nxt]-C.p[nxtpos];
                if(abs(v3^v4)>=abs(v1^v2)) pos=nxtpos;
                else break;
            }
            Point v1=C.p[l]-C.p[pos],v2=C.p[nxt]-C.p[pos];
            ans=max(ans,abs(v1^v2)+now+(C.p[nxt]^C.p[l]));
            r=nxt;
        }
        printf("%.12Lf\n",(long double)(1.0*ans/2.0));
    }
    
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

3
3 1
0 0
1 0
0 1
8 3
1 2
3 1
5 1
7 3
8 6
5 8
3 7
1 5
7 2
3 6
1 1
3 1
7 1
8 1
5 6
4 6

output:

0.500000000000
26.500000000000
20.000000000000

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

1
4 2
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
-1000000000 1000000000

output:

4000000000000000000.000000000000

result:

ok found '4000000000000000000.000000000', expected '4000000000000000000.000000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 13ms
memory: 3848kb

input:

14246
7 5
-999999980 -999999988
-999999979 -999999984
-999999978 -999999978
-999999979 -999999972
-1000000000 -999999998
-999999993 -1000000000
-999999984 -999999993
6 1
-999999987 -999999987
-999999993 -999999981
-999999998 -999999986
-1000000000 -999999996
-999999995 -1000000000
-999999986 -999999...

output:

230.500000000000
78.000000000000
173.000000000000
46.000000000000
161.500000000000
25.000000000000
224.000000000000
78.000000000000
42.000000000000
75.000000000000
113.500000000000
179.000000000000
227.000000000000
224.500000000000
459.500000000000
33.500000000000
323.000000000000
208.000000000000
1...

result:

ok 14246 numbers

Test #4:

score: 0
Accepted
time: 16ms
memory: 3700kb

input:

14244
6 4
-547850284 -481269250
-1000000000 -714647423
-533299247 -1000000000
656886478 -769438616
700263718 -430440203
106399420 -305601756
10 3
-466281822 506862192
-907094238 85058839
-1000000000 -281869646
-855490497 -478229011
-112167057 -1000000000
147495199 -983428035
704507845 -902383045
828...

output:

732791354437434368.000000000000
1492466916906283520.000000000000
1571608624804175360.000000000000
853722168331793664.000000000000
1841579555796117760.000000000000
186812625650844480.000000000000
1374931373816256512.000000000000
1396248766527417088.000000000000
300749428982044480.000000000000
1597680...

result:

ok 14244 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 3900kb

input:

1000
100 84
-638427072 -696806030
-574275620 -741577840
-517724956 -779879773
-440790977 -831653888
-371696794 -867523797
-292070733 -904513365
-246157947 -920874374
-196125497 -936669098
-120139525 -960537360
-54479671 -978537127
-11534554 -987883373
26411313 -994847568
72263671 -1000000000
1168709...

output:

2901829084045602816.000000000000
327527198347053248.000000000000
1734256029955228928.000000000000
2416380865036326400.000000000000
935891084317887488.000000000000
2828414703961765376.000000000000
2101460694807832576.000000000000
2426931532374706176.000000000000
2679372534658023424.000000000000
27623...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 7ms
memory: 3716kb

input:

100
1000 168
-808847262 -517721134
-803072067 -525448193
-798730847 -531136476
-796502549 -534032203
-791151313 -540928191
-786588703 -546785604
-782732315 -551644783
-780071973 -554976222
-774771946 -561591700
-769683918 -567839156
-769554831 -567997637
-766249149 -572042373
-759870835 -579831042
-...

output:

1028923552719996032.000000000000
2832301779860078592.000000000000
2848011247470070272.000000000000
2506790184987356672.000000000000
2622377875251076096.000000000000
2556381233480029184.000000000000
2780396909089778176.000000000000
1735531899101324032.000000000000
987263293126023936.000000000000
2933...

result:

ok 100 numbers

Test #7:

score: 0
Accepted
time: 7ms
memory: 4136kb

input:

10
10000 3930
374998960 871320826
374305646 871707307
373541784 872131442
372913079 872480119
372247815 872848960
372082544 872940283
371300533 873371391
370696772 873703715
369897687 874143282
369135422 874562333
368787728 874753324
368396307 874968013
367915968 875230945
367376687 875525844
367147...

output:

2095908706043761664.000000000000
2881509906421599232.000000000000
860651843537664128.000000000000
2225240521612313856.000000000000
911084696371304576.000000000000
2134470965837802240.000000000000
2924168382633125376.000000000000
1052994530795952384.000000000000
2555680635181519872.000000000000
27032...

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 7ms
memory: 4552kb

input:

1
100000 91077
937469288 -231959258
937491476 -231891836
937502721 -231857664
937522226 -231798381
937545631 -231727224
937556752 -231693411
937581626 -231617767
937594048 -231579990
937605611 -231544822
937620487 -231499574
937644936 -231425160
937656870 -231388830
937680141 -231317975
937699154 -2...

output:

2889987064399269888.000000000000

result:

ok found '2889987064399269888.000000000', expected '2889987064399269888.000000000', error '0.000000000'