QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694702 | #6517. Computational Geometry | liubw_ | WA | 2ms | 4044kb | C++20 | 3.5kb | 2024-10-31 18:29:46 | 2024-10-31 18:29:47 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define max(A,B) (A>B? A:B)
#define min(A,B) (A<B? A:B)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pir(X) pair<X,X>
#define mpr(A,B) make_pair(A,B)
#define fr first
#define sc second
#define sq(x) ((x)*(x))
using namespace std;
const int N=5e3+10;
const db inf=5e18;
const db eps=1e-7;
class Point{
public:
db x,y,arctan;
Point(db _x=0,db _y=0) : x(_x),y(_y) {}
void read() { cin>>x>>y; }
void print(string s=""){
cerr<<" Point ["<<s<<"] : x="<<x<<" y="<<y<<'\n';
}
Point turn(const db k) const {
Point p(x*cos(k)-y*sin(k),x*sin(k)+y*cos(k));
return p;
}
Point operator - (const Point &o) const{
Point ret(x-o.x,y-o.y);
return ret;
}
Point operator + (const Point &o) const{
Point ret(x+o.x,y+o.y);
return ret;
}
bool operator == (const Point &o) const{
return x==o.x&&y==o.y;
}
}p[N];
class Vector2{
public:
db x,y;
Vector2(db _x=0,db _y=0): x(_x),y(_y) {}
void read() { cin>>x>>y; }
void print(string s=""){
cerr<<" Vector2 ["<<s<<"] : x="<<x<<" y="<<y<<'\n';
}
void assign(db _x,db _y) { x=_x, y=_y; }
void assign(const Point &a,const Point &b){ // 向量赋值,注意前后形参的顺序
x=a.x-b.x;
y=a.y-b.y;
}
Vector2 operator + (const Vector2 &o) const {
return (Vector2){x+o.x,y+o.y};
}
Vector2 operator - (const Vector2 &o) const {
return (Vector2){x-o.x,y-o.y};
}
Vector2 operator * (const db a) const {
return (Vector2){a*x,a*y};
}
db operator * (const Vector2 &o) const {
return x*o.x+y*o.y;
}
db operator ^ (const Vector2 &o) const {
return x*o.y-y*o.x;
}
db len() const{
return sqrt(x*x+y*y);
}
db len2() const{
return x*x+y*y;
}
Vector2 unit() const {
db len=sqrt(x*x+y*y);
Vector2 l(x/len,y/len);
return l;
}
};
db dis(Point a,Point b){
return sq(a.x-b.x)+sq(a.y-b.y);
}
bool In_line(const Point &a,const Point &b,const Point &c){ // 判断 b 是否在直线 a-c 上
// if(!(min(a.x,c.x)<=b.x+eps&&b.x<=max(a.x,c.x)+eps)) return false;
// if(!(min(a.y,c.y)<=b.y+eps&&b.y<=max(a.y,c.y)+eps)) return false;
Vector2 l1,l2;
l1.assign(a,b),l2.assign(c,b);
return fabs(l1^l2)<=eps;
};
db f[N][N];
int n;
void slv(){
cin>>n;
for(int i=0;i<n;i++) p[i].read();
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++) f[i][j]=inf;
// }
for(int i=0;i<n;i++) f[i][(i+1)%n]=dis(p[i],p[(i+1)%n]);
for(int l=2;l<=n;l++){
for(int i=0;i<n;i++){
int j=(i+l)%n;
f[i][j]=max(dis(p[i],p[j]),max(f[(i+1+n)%n][j],f[i][(j-1+n)%n]));
}
}
db ans=inf;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
// cerr<<" i="<<i<<" j="<<j<<" f="<<f[i][j]<<" dis="<<dis(p[i],p[j])<<'\n';
if(In_line(p[i],p[j],p[(i+1)%n])) continue;
if(In_line(p[(i-1+n)%n],p[j],p[i])) continue;
ans=min(ans,f[i][j]+f[j][i]);
}
}
cout<<(ll)round(ans)<<'\n';
return;
}
void fst_IO(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int main(){
fst_IO();
int T;
cin>>T;
while(T--){
slv();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4044kb
input:
2 4 1 0 2 0 1 1 0 0 6 10 4 9 7 5 7 4 5 6 4 9 3
output:
4 44
result:
ok 2 number(s): "4 44"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3964kb
input:
713 8 8 25 3 15 0 5 10 0 19 2 24 6 23 15 15 34 8 25 16 18 25 10 32 1 23 0 14 21 0 27 2 32 6 7 16 15 8 20 1 16 0 12 16 0 21 1 24 5 7 15 1 18 0 24 8 27 15 4 19 0 17 7 8 4 10 20 0 30 15 0 14 10 6 15 0 24 10 21 14 12 14 7 11 0 3 7 18 7 16 9 12 10 6 9 0 4 5 0 15 1 9 0 23 8 13 14 6 24 0 34 1 41 11 37 20 1...
output:
1075 1389 706 687 1550 497 300 1668 471 162 519 190 786 983 367 930 580 524 509 275 617 298 146 1330 494 965 599 1321 866 1210 233 398 560 1548 871 938 366 500 371 1118 1222 1994 712 586 858 624 697 575 1274 882 1035 406 934 670 990 1231 513 2871 939 2735 1610 834 721 585 203 198 1666 617 1166 326 2...
result:
ok 713 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 4032kb
input:
723 6 219724071 0 454078946 131628774 497404433 165947891 427997418 299842932 68283732 510015817 0 327227140 5 277969751 0 576739203 275664810 244855879 638262097 13873538 700473186 0 59956198 10 69526931 509564969 0 395765436 101436487 0 273066511 46581979 904969235 467379058 942000353 535129295 93...
output:
320990950510053376 818929519958899456 1129629590903770112 711353303900820480 683190682500395904 594439231930042496 659610359567672192 1233154227545010176 845514798756141568 410893515758460160 293647337551438592 889581785464512512 1220017957053127424 1180615726625079808 993125871111020800 88416805922...
result:
wrong answer 1st numbers differ - expected: '320990950510053393', found: '320990950510053376'