結果

問題 No.96 圏外です。
ユーザー ciel
提出日時 2014-12-08 00:16:32
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 3,374 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 103,052 KB
実行使用メモリ 15,832 KB
最終ジャッジ日時 2024-12-24 07:49:00
合計ジャッジ時間 4,218 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:90:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~
main.cpp:102:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |                         scanf("%d%d",&v[i].first,&v[i].second);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cmath>
using namespace std;
//union_find
class union_find{
int *parent,n;
public:
int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
union_find(int _n){
n=_n;
parent=new int[n];
for(int i=0;i<n;i++)parent[i]=i;
}
~union_find(){delete []parent;}
int unite(int a,int b){
int x=root(a),y=root(b);if(x==y)return 0;
parent[y]=x;
return 1;
}
};
//farthest pair (from spaghetti source)
typedef double number;
typedef complex<number> P;
namespace std {
bool operator < (const P& a, const P& b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
b -= a; c -= a;
if (cross(b, c) > 0) return +1; // counter clockwise
if (cross(b, c) < 0) return -1; // clockwise
if (dot(b, c) < 0) return +2; // c--a--b on line
if (norm(b) < norm(c)) return -2; // a--b--c on line
return 0;
}
vector<P> convex_hull(vector<P> &ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
vector<P> ch(2*n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
ch.resize(k-1);
return ch;
}
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
number convex_diameter(const vector<P> &pt) {
const int n = pt.size();
int is = 0, js = 0;
for (int i = 1; i < n; ++i) {
if (imag(pt[i]) > imag(pt[is])) is = i;
if (imag(pt[i]) < imag(pt[js])) js = i;
}
number maxd = norm(pt[is]-pt[js]);
int i, maxi, j, maxj;
i = maxi = is;
j = maxj = js;
int t=1000; //wtf?
do {
if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
else i = (i+1) % n;
if (norm(pt[i]-pt[j]) > maxd) {
maxd = norm(pt[i]-pt[j]);
maxi = i; maxj = j;
}
t--;
} while (t&&(i != is || j != js));
return maxd;
}
int main(){
int N;
scanf("%d",&N);
if(N==0){
puts("1");
return 0;
}
unordered_map<int,vector<P> >z;
{
unordered_set<int>kind_x,kind_y;
vector<pair<int,int> >v(N);
for(int i=0;i<N;i++){
scanf("%d%d",&v[i].first,&v[i].second);
kind_x.insert(v[i].first);
kind_y.insert(v[i].second);
}
if(kind_x.size()<kind_y.size()*10)for(int i=0;i<N;i++)swap(v[i].first,v[i].second);
sort(v.begin(),v.end());
union_find uf(N);
for(int i=0;i<N-1;i++){
int upper=upper_bound(v.begin(),v.end(),make_pair(v[i].first+10,9999999))-v.begin();
for(int j=i+1;j<upper;j++){
if(
(v[i].first-v[j].first)*(v[i].first-v[j].first) + (v[i].second-v[j].second)*(v[i].second-v[j].second)
<=100)uf.unite(i,j);
}
}
for(int i=0;i<N;i++){
int r=uf.root(i);
z[r].push_back(complex<number>(v[i].first,v[i].second));
}
}
number result=0;
for(auto &it:z){
auto hull=convex_hull(it.second);
if(hull.size()<2)continue;
result=max(result,convex_diameter(hull));
}
printf("%.9f\n",sqrt(result)+2);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0