답안 #17552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17552 2015-12-27T07:38:41 Z gs14004 두 개의 원 (balkan11_2circles) C++14
60 / 100
226 ms 6680 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<double, double> pi;
const double eps = 1e-5;

int n;
int x[50005], y[50005];
 
struct line{
    double a, b, c;
}v[50005];
 
pi rotate(pi a, pi b, double q){
    int dx = a.second - b.second;
    int dy = b.first - a.first;
    double pyth = hypot(dx, dy);
    return pi(b.first + (dx / pyth) * q, b.second + (dy / pyth) * q);
}
 
pi cross(line p, line q){
    double base = p.a * q.b - p.b * q.a;
    if(fabs(base) < eps) return pi(1e9, 1e9);
    return pi((p.b * q.c - q.b * p.c) / base, (p.c * q.a - q.c * p.a) / base);
}
 
bool ccw(pi a, pi b, pi c){
    double dx1 = b.first - a.first;
    double dy1 = b.second - a.second;
    double dx2 = c.first - a.first;
    double dy2 = c.second - a.second;
    return dx1 * dy2 > dy1 * dx2;
}

double func(line a, pi b){
    return a.a * b.first + a.b * b.second + a.c;
}

bool bad;

bool low(line a, line b, line c){
	pi t = cross(a, c);
	if(fabs(t.first - 1e9) <= eps){
		if(func(a, cross(b, c)) <= 0){
			bad = 1;
		}
		return 0;
	}
	if(func(c, cross(a, b)) <= 0){
		if(func(b, cross(a, c)) <= 0){
			bad = 1;
		}
		return 1;
	}
	return 0;
}

void get_points(vector<pi> &ret){
	bad = 0;
	deque<line> dq;
	for(int i=0; i<n; i++){
		while(dq.size() >= 2 && low(dq[dq.size()-2], dq.back(), v[i])){
			dq.pop_back();
		}
		dq.push_back(v[i]);
	}
	while(dq.size() >= 3 && low(dq.back(), dq[0], dq[1])){
		dq.pop_front();
	}
	if(bad) return;
	if(dq.size() <= 2) return;
	for(int i=0; i<dq.size()-1; i++){
		ret.push_back(cross(dq[i], dq[i+1]));
	}
	ret.push_back(cross(dq.back(), dq.front()));
}
 
bool trial(double d){
    for(int i=0; i<n; i++){
        int a = y[i] - y[i+1];
        int b = x[i+1] - x[i];
        pi loc = rotate(pi(x[i], y[i]), pi(x[i+1], y[i+1]), d);
        v[i] = {1.0 * a, 1.0 * b, - a * loc.first - b * loc.second}; // ax + by + c >= 0
    }
    vector<pi> p;
    get_points(p);
    if(p.empty()) return 0;
    auto dist = [&](pi a, pi b){
    	return hypot(b.first - a.first, b.second - a.second);
    };
    int pt = 0;
    for(int i=0; i<p.size(); i++){
    	while(pt+1 < p.size() && dist(p[i], p[pt]) < dist(p[i], p[pt+1])){
    		pt++;
    	}
    	if(dist(p[i], p[pt]) >= 2 * d) return 1;
    }
    return 0;
}
 
int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%d %d",&x[i],&y[i]);
    }
    x[n] = x[0], y[n] = y[0];
    double s = 0, e = 1e7;
    for(int i=0; i<50; i++){
        double m = (s+e)/2;
        if(trial(m)) s = m;
        else e = m;
    }
    printf("%.3f",s);
}

Compilation message

2circles.cpp: In function 'void get_points(std::vector<std::pair<double, double> >&)':
2circles.cpp:90:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<dq.size()-1; i++){
                ^
2circles.cpp: In function 'bool trial(double)':
2circles.cpp:110:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<p.size(); i++){
                   ^
2circles.cpp:111:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while(pt+1 < p.size() && dist(p[i], p[pt]) < dist(p[i], p[pt+1])){
                 ^
2circles.cpp: In function 'int main()':
2circles.cpp:120:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
2circles.cpp:122:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x[i],&y[i]);
                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3600 KB Output is correct
2 Correct 0 ms 3600 KB Output is correct
3 Correct 0 ms 3600 KB Output is correct
4 Correct 0 ms 3600 KB Output is correct
5 Correct 9 ms 3736 KB Output is correct
6 Correct 63 ms 4268 KB Output is correct
7 Incorrect 53 ms 4020 KB Output isn't correct
8 Incorrect 66 ms 4364 KB Output isn't correct
9 Incorrect 153 ms 4508 KB Output isn't correct
10 Incorrect 226 ms 6680 KB Output isn't correct