QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#683807#9520. Concave HullsusanzhishenAC ✓229ms49100kbC++206.9kb2024-10-27 23:59:132024-10-30 01:33:58

Judging History

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

  • [2024-10-30 01:33:58]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:229ms
  • 内存:49100kb
  • [2024-10-30 01:29:57]
  • hack成功,自动添加数据
  • (/hack/1083)
  • [2024-10-27 23:59:14]
  • 评测
  • 测评结果:100
  • 用时:242ms
  • 内存:49832kb
  • [2024-10-27 23:59:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> PII;
#define db double
const db eps = 1e-12;
const db inf = 1e20;
const db PI = acos(-1.0);
inline int sgn(db x) {return x < -eps ? -1 : x > eps;}
inline db sqr(db x) { return x*x; }
inline db mysqrt(db x) { return sqrt(max((double)0.0, x)); }
//注意y1给系统占了
const int N=3e5+10;
const int M=1e3+10;
int mod=1e9+7;
/*========================================================*\
| Point 类
| 							类内函数
| Point(P x = 0, P y = 0)					- 默认构造函数
| input()									- 读入一个点
| operator == 								- NULL
| operator <								- 用于排序
| operator +								- 返回Point
| operator -								- 返回Point
| operator *								- 返回Point
| operator /								- 返回Point
| len()										- 返回长度
| len2()									- 返回长度平方		
| trunc(db len)								- 长度变为len
| rotleft()									- 逆时针转π/2, 返回Point
| rotright()								- 顺时针转π/2, 返回Point
| rotate(P p, db ang)						- 绕p逆时针转ang
| 							类外函数
| *基础功能
| Cross(P a, P b)							- NULL
| Cross(P pt, P a, P b)						- NULL
| Dot(P a, P b)								- NULL
| Dot(P pt, P a, P b)						- NULL
| Dist(P a, P b)							- NULL
| Len(a)									- 返回a的长度
| Len2(a) 									- 返回a的长度平方
| rad(P p, P a, P b) 						- 返回∠apb	
| Complex类补充
\*========================================================*/
struct Point {
    db x, y;
    Point (db x=0, db y=0): x(x), y(y) {}
    void input() { scanf("%lf%lf", &x, &y); }
    bool operator == (Point r) { return sgn(x-r.x)==0 && sgn(y-r.y)==0; }
    // bool operator < (Point r) { return sgn(x-r.x)==0 ? y < r.y : x < r.x; }
    Point operator + (Point r) { return Point (x+r.x, y+r.y); }
    Point operator - (Point r) { return Point (x-r.x, y-r.y); }
    Point operator * (db r) { return Point (x*r, y*r); }
    Point operator / (db r) { return Point (x/r, y/r); }
    db len() { return mysqrt(x*x+y*y); }
    db len2() { return x*x + y*y; }
    // 化为长度为 r 的向量
    Point trunc(db len) {
        db l = mysqrt(x * x + y * y);
        if (! sgn(l)) return *this;
        len /= l;
        return Point (x*len, y*len);
    }
    // 逆时针旋转 90 度
    Point rotleft() { return Point (-y, x); }
    // 顺时针旋转 90 度
    Point rotright() { return Point (y, -x); }
    // 绕着 p 点逆时针旋转 ang
    Point rotate (Point p, db ang) {
        Point v = (*this) - p;
        db c = cos(ang), s = sin(ang);
        return Point (p.x + v.x*c - v.y*s, p.y + v.x*s + v.y*c);
    }
};
/******************************\
| 			基础功能
\******************************/
db Cross (Point a, Point b) { return a.x*b.y - a.y*b.x; }
db Cross (Point pt, Point a, Point b) { return Cross(a-pt, b-pt); }
db Dot (Point a, Point b) { return a.x*b.x + a.y*b.y; }
db Dot (Point pt, Point a, Point b) { return Dot (a-pt, b-pt); }
db Dist (Point a, Point b) { return mysqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); }
db Len (Point a) { return mysqrt(a.x*a.x + a.y*a.y); }
db Len2 (Point a) { return a.x*a.x + a.y*a.y; }
// 计算 pa 和 pb 的夹角,  就是求这个点看 a, b 所成的夹角, 测试 LightOJ 1203
db rad(Point p, Point a, Point b) { 
    return fabs(atan2(fabs(Cross(p, a, b)), Dot(p, a, b) )); 
}
/******************************\
| 			Complex补充
\******************************/
struct Complex {
    db x, y;
    Complex(db x = 0, db y = 0) : x(x), y(y) {}
    Complex operator + (Complex b) {return Complex(x + b.x, y + b.y);}
    Complex operator - (Complex b) {return Complex(x - b.x, y - b.y);}
    Complex operator * (Complex b) {return Complex(x * b.x - y * b.y, x * b.y + y * b.x);}
};
// db disptl(Line v, Point p) {
//     return fabs(Cross(v.s, p, v.e)) / v.length(); // length = [](){return Dist(v.s, v.e);}
// }
// Andrew 算法
// 坐标排序 O(nlogn), 测试: 洛谷P2742;凸包稳定相关: POJ1228
// 这里有两种排序方法
// 1. 优先按 y 排序, 如果 y 相同, 按 x 排序, 起点是最下面的点, 如下面代码体现
// 2. 优先按 x 排序, 如果 x 相同, 按 y 排序, 起点是最左边的点
bool operator < (Point a, Point b) { 
	if (sgn(a.y - b.y) == 0) return a.x < b.x;
    return a.y < b.y;
}
int andrew(Point *p, Point *ch, int n) {  // 返回值是凸包的顶点数
    sort (p, p + n);   // 排序
    n = unique(p, p + n) - p; // 去除重复的点
    int v = 0;
    // 求下凸包, 如果 p[i] 是右拐弯的, 则这个点不在凸包中, 往回退
    for (int i = 0; i < n; i ++) {
        while (v > 1 && sgn(Cross(ch[v-2], ch[v-1], p[i])) <= 0) v --;
        ch[v ++] = p[i];
    }
    int j = v;
    // 求上凸包
    for (int i = n - 2; i >= 0; i --) {
        while (v > j && sgn(Cross(ch[v-2], ch[v-1], p[i])) <= 0) v --;
        ch[v ++] = p[i];
    }
    if (n > 1) v --;
    return v;
}
db area(Point a, Point b, Point c){
    Point AB=b-a,AC=c-a;
    return fabs(AB.x*AC.y-AB.y*AC.x);
}
db polygonarea(Point* p, int n) {
    db ans = 0;
    p[n] = p[0];
    for (int i = 0; i < n; i ++) 
        ans += Cross(p[i], p[i+1]);
    return fabs(ans) ;           // 面积有正负, 需根据题意来判断要不要取绝对值
}
db disptl(Point A, Point B, Point p) {
    return fabs(Cross(A, p, B)) / Dist(A, B); // length = [](){return Dist(v.s, v.e);}
}
Point ch1[N], ch2[N],p1[N],p2[N];
int vis[N];
void solve(){
    int n;cin>>n;
    for(int i=0;i<=n;i++) p1[i].x=p1[i].y=p2[i].x=p2[i].y=ch1[i].x=ch1[i].y=ch2[i].x=ch2[i].y=vis[i]=0;
    map<PII,int>mp;
    for(int i=0;i<n;i++) cin>>p1[i].x>>p1[i].y;
    int m1 = andrew(p1, ch1, n);
    if(m1==n){
        cout<<"-1\n";
        return ;
    }
    for(int i=0;i<n;i++) mp[{p1[i].x,p1[i].y}]=i;
    // cout<<"\n";
    for(int i=0;i<m1;i++){
        vis[mp[{ch1[i].x,ch1[i].y}]]=1;
    }
    int sp=0;
    for(int i=0;i<n;i++){
        if(!vis[i]) p2[sp++]=p1[i];
        // cout<<vis[i]<<" ";
    }
    int m2 = andrew(p2, ch2, sp);
    double S=polygonarea(ch1, m1);
    int idx=0;
    double ans=0;
    // cout<<"\n";
    for(int i=0;i<m1;i++){
        double fz=1e19,mu=1;
        Point A=ch1[i],B=ch1[(i+1)%m1];
        while(1){
            double fz1=fabs(Cross(A,B,ch2[idx]))*fabs(Cross(A,B,ch2[idx]));
            double mu1=(A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
            if(fz1*mu<fz*mu1) fz=fz1,mu=mu1;
            else break;
            idx=(idx+1)%m2;
        }
        idx=(idx-1+m2)%m2;
        ans=max(ans,S-area(A,B,ch2[idx]));
    }
    cout<<(int)ans<<"\n";
}

signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr),cout.tie(nullptr);
    int _;
    _=1;
    cin>>_;
    while(_--){
        solve();
    }
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 42188kb

input:

2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1

output:

40
-1

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 11ms
memory: 41900kb

input:

10
243
-494423502 -591557038
-493438474 -648991734
-493289308 -656152126
-491185085 -661710614
-489063449 -666925265
-464265894 -709944049
-447472922 -737242534
-415977509 -773788538
-394263365 -797285016
-382728841 -807396819
-373481975 -814685302
-368242265 -818267002
-344482838 -833805545
-279398...

output:

2178418010787347715
1826413114144932145
1651687576234220014
1883871859778998985
2119126281997959892
894016174881844630
2271191316922158910
1998643358049669416
1740474221286618711
1168195646932543192

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 106ms
memory: 41836kb

input:

1000
125
64661186 -13143076
302828013 -185438065
-418713797 -191594241
430218126 -397441626
354327250 -836704374
149668812 -598584998
311305970 66790541
199720625 -592356787
468137 -584752683
258775829 96211747
-358669612 -134890109
-129221188 -998432368
-277309896 -140056561
356901185 420557649
-51...

output:

1986320445246155278
1900093336073022078
1612088392301142476
2012259136539173407
1819942017252118749
1772230185841892196
1164835025329039520
1527446155241140517
1807368432185303666
1236918659444944569
1306839249967484778
1984123720246784099
1868728080720036006
667458140583450322
2127932992585026491
4...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 142ms
memory: 41348kb

input:

10000
9
484630042 51929469
-40468396 -517784096
98214104 -103353239
629244333 -475172587
106398764 153884485
49211709 -44865749
1 10
166321833 -247717657
406208245 668933360
13
548702216 -631976459
37150086 -292461024
707804811 -486185860
239775286 -903166050
10096571 -541890068
686103484 558731937
...

output:

950319193795831919
1661025342421008544
1285164852091455548
1159924751776806668
1206071151805176722
794021230296144371
699991678992587791
1133990718508584290
1486311831172661605
984875884297072200
1327767982175057345
758247019006396699
1355381234262206155
1139262078529131471
1613462877860621700
12392...

result:

ok 10000 lines

Test #5:

score: 0
Accepted
time: 229ms
memory: 42328kb

input:

100
439
471536154 -312612104
155692036 -937312180
-461624056 -357636609
236656684 -911414873
-288656914 -74788431
-465779694 -381475149
-334197401 -903065737
491513067 -447615916
337664889 -852236281
-281689379 -53519178
-159101704 -920779200
-326159514 -95396204
21868593 -994282736
488425383 -41046...

output:

1973162724053130487
2054612790507830954
1726805687754843724
1699420177872986528
2129388571309147631
2198295137903288810
1697185883164440272
1219697450095721478
2027023581922285255
1674691247127206655
1673105966817209954
2179188692918747442
2146544318743443141
2230356305133660648
1676850321902993764
...

result:

ok 100 lines

Test #6:

score: 0
Accepted
time: 198ms
memory: 43312kb

input:

100
1362
-467257672 -466669
-467054869 -478108
-466973270 -481776
-466556983 -499770
-466329414 -508693
-466248017 -511805
-466158865 -513786
-466101273 -515035
-465927700 -518748
-465717624 -522106
-465303448 -528127
-465124548 -530726
-464649746 -536693
-464554872 -537799
-464478196 -538680
-46416...

output:

1666097696993497
1791366071767866
1806187278469532
1683419854733713
1685891971828916
1730190225081651
1787048201197565
1850308098208660
1710694884375502
1826363113637639
1816375352374659
2047431269497691
1549806516003854
1829438662895747
1678707854135065
1687423392883819
2121960009997761
16687219538...

result:

ok 100 lines

Test #7:

score: 0
Accepted
time: 114ms
memory: 46724kb

input:

2
62666
-486101704 -505730259
-486101698 -506082699
-486101689 -506111362
-486101682 -506126031
-486101528 -506293759
-486101259 -506556385
-486101196 -506613483
-486101154 -506648604
-486100935 -506831392
-486100631 -507083675
-486100470 -507199151
-486100233 -507368923
-486100193 -507397039
-48609...

output:

2178736946152219010
1825181940245096152

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 228ms
memory: 48888kb

input:

2
100000
301945097 76373292
467957663 -286424714
8245445 -597212507
-474204621 -708828667
184159460 105942538
443435905 -429212625
490658771 -382198656
82512047 -612522436
-228221388 -965890088
394789011 -145801151
-106120174 -528202395
428939626 -194437311
497429477 -527407728
365739746 -114818962
...

output:

2502889432701099511
2267250485735988121

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 228ms
memory: 49100kb

input:

2
100000
221128057 -975244780
-618765360 -785575858
422567455 -906331476
-988680318 -150037424
-929870145 367887908
-757813541 -652471177
291995621 -956419655
-785381507 619012026
468864522 -883270094
-588416522 808557973
859345881 511394814
988105866 153775152
216931298 -976186873
467050734 8842305...

output:

6283183114882825575
6283183188903854361

result:

ok 2 lines

Test #10:

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

input:

7
5
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
1 0
-1 0
5
1000000000 1000000000
-1000000000 -1000000000
-2 0
-1 0
1 -1
6
1000000000 1000000000
-1000000000 -1000000000
-3 0
-1 0
0 -1
1 -1
4
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
-1000000000 1000...

output:

4000000000000000000
7000000000
9000000001
-1
6000000002000000000
7999999998000000000
-1

result:

ok 7 lines

Extra Test:

score: 0
Extra Test Passed