답안 #585018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585018 2022-06-28T08:57:43 Z 조영욱(#8382) Fences (JOI18_fences) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

int n,s;
typedef pair<int,int> P;
P p[4];

long long ccw(P a,P b,P c) {
    return a.first*b.second+b.first*c.second+c.first*a.second-a.second*b.first-b.second*c.first-c.second*a.first;
}

bool cross(P a,P b,P c,P d) {
    if (ccw(a,b,c)*ccw(a,b,d)>0) {
        return false;
    }
    if (ccw(c,d,a)*ccw(c,d,b)>0) {
        return false;
    }
    return true;
}

long double dist(P a,P b) {
    return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}

int main(void) {
    scanf("%d %d",&n,&s);
    p[0]=P(s,s);
    p[1]=P(s,-s);
    p[2]=P(-s,-s);
    p[3]=P(-s,s);
    P p1,p2;
    scanf("%d %d %d %d",&p1.first,&p1.second,&p2.first,&p2.second);
    long double ret=8*s;
    //printf("%d\n",cross(p2,p[1],p[0],p[1]));
    for(int i=0;i<4;i++) {
        for(int j=0;j<4;j++) {
            if (i==j) {
                continue;
            }
if (cross(p1,p[i],p2,p[j])) continue;
            bool flag=true;
            for(int k=0;k<4;k++) {
                if (i!=k&&i!=(k+1)%4&&cross(p[k],p[(k+1)%4],p1,p[i])) {
                    flag=false;
                    break;
                }
                if (j!=k&&j!=(k+1)%4&&cross(p[k],p[(k+1)%4],p2,p[j])) {
                    flag=false;
                    break;
                }
            }
            if (!flag) {
                continue;
            }
            flag=false;
            if (!cross(p1,p[(i+1)%4],p2,p[(j+3)%4])) {
                flag=true;
            }
            int cnt=0;
            int one=i;
            int two=j;
                while (one!=two) {
                    one=(one+(flag?1:3))%4;
                    cnt++;
                }
            //printf("%d %d %d\n",i,j,cnt);
            ret=min(ret,(long double)cnt*s*2.0+dist(p1,p[i])+dist(p2,p[j]));
        }
    }
    printf("%.12Lf",ret);
}

Compilation message

fences.cpp: In function 'int main()':
fences.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d %d",&n,&s);
      |     ~~~~~^~~~~~~~~~~~~~~
fences.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d %d %d %d",&p1.first,&p1.second,&p2.first,&p2.second);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -