QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386267 | #5809. Min Perimeter | CharlieVinnie | 0 | 0ms | 0kb | C++23 | 5.5kb | 2024-04-11 14:53:37 | 2024-04-11 14:53:38 |
answer
#include "bits/stdc++.h"
// #define DEBUG
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](){}()
#define debuga(...) [](){}()
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
namespace FastIO{
const int BUF_SIZ=1<<16;
char in_buf[BUF_SIZ],*got_pos=in_buf,*read_pos=in_buf,out_buf[BUF_SIZ],*write_pos=out_buf;
inline char get_next_char(){if(read_pos==got_pos){got_pos=read_pos=in_buf;got_pos+=fread(got_pos,sizeof(char),BUF_SIZ,stdin);}return*(read_pos++);}
inline void flush_output(){fwrite(out_buf,sizeof(char),write_pos-out_buf,stdout);write_pos=out_buf;}
inline void put_char(char ch){*(write_pos++)=ch;if(write_pos==out_buf+BUF_SIZ)flush_output();}
#define FASTIO_READ_NEGATIVE
#ifndef FASTIO_READ_NEGATIVE
template<typename T> inline void read(T& res){char ch;while(!isdigit(ch=get_next_char()));res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');}
#else
template<typename T> inline void read(T& res){char ch;bool flg=0;while(!isdigit(ch=get_next_char()))flg|=ch=='-';res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');if(flg)res=-res;}
#endif
template<typename T> inline void write(T x){if(!x){put_char('0');return;}static int lis[25],*lp=lis;while(x){*(++lp)=x%10;x/=10;}while(lp!=lis)put_char((*(lp--))+'0');}
template<typename T> inline void writeln(const T& x){write(x);put_char('\n');}
template<typename T> inline void writesp(const T& x){write(x);put_char(' ');}
class _IO_Flusher{public:~_IO_Flusher(){flush_output();}}__Flusher;
class IStream{public:
template<typename T> inline IStream& operator>>(T& x){read(x);return *this;}
inline IStream& operator>>(char* str){char ch;while(isspace(ch=get_next_char()));(*(str++))=ch;while(!isspace(ch=get_next_char())){if(ch==EOF)break;(*(str++))=ch;}*str=0;return *this;}
}Cin;
class OStream{public:
template<typename T> inline enable_if_t<is_integral<T>::value,OStream&> operator<< (const T& x){write(x);return *this;}
inline OStream& operator<< (const char& ch){put_char(ch);return *this;}
inline OStream& operator<< (const char* str){for(const char* p=str;*p;put_char(*(p++)));return *this;}
}Cout;
}
using namespace FastIO;
#define cin Cin
// #define cout Cout
mt19937 rng(19031253);
template<typename _Key,typename _Val,int N>
class HashTable{
static constexpr int mod = 1e6+7;
int head[mod],nxt[N],tot,vis[mod],V; _Val val[N]; _Key key[N];
inline int hash(_Key k) { int res=k%mod; res=(res+mod)%mod; return res; }
public:
void clear() { tot=0; V++; }
bool count(_Key k){
int h=hash(k); if(vis[h]!=V) vis[h]=V,head[h]=0;
int u=head[h]; while(u&&key[u]!=k) u=nxt[u];
return u!=0;
}
_Val& operator[] (_Key k){
int h=hash(k); if(vis[h]!=V) vis[h]=V,head[h]=0;
int u=head[h]; while(u&&key[u]!=k) u=nxt[u];
if(!u){
nxt[++tot]=head[h]; val[tot]=0; head[h]=tot; key[tot]=k; return val[tot];
}
else return val[u];
}
};
constexpr int N=2e6+5;
HashTable<ll,int,N*2> O;
// map<ll,int> O;
int n,tmp[N],lis[N][20],lcnt[N],tot; double X[N],Y[N];
inline double dist(int u,int v) { return sqrt((X[u]-X[v])*(X[u]-X[v])+(Y[u]-Y[v])*(Y[u]-Y[v])); }
signed main(){
// Fin("data.in"); //Fout("triangle.out");
// Fin("triangle2.in");
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
int T; cin>>T; while(T--){
cin>>n; double theta=uniform_real_distribution<double>(0,2*acos(-1.0))(rng), cost=cos(theta), sint=sin(theta);
For(i,1,n){
int x,y; cin>>x>>y; X[i]=x; Y[i]=y;
X[i]=x*cost-y*sint;
Y[i]=x*sint+y*cost;
}
iota(tmp+1,tmp+1+n,1); shuffle(tmp+1,tmp+1+n,rng); tot=0; O.clear();
double ans=3e9;
For(_,1,n){
int u=tmp[_]; ll x=X[u]/ans/2,y=Y[u]/ans/2;
int hh[200]={0},hcnt=0;
For(dx,-1,1) For(dy,-1,1){
ll qwq=(x+dx)*ll(2e9)+(y+dy);
if(O.count(qwq)){
int o=O[qwq]; For(i,0,lcnt[o]-1) assert(hcnt!=199),hh[++hcnt]=lis[o][i];
}
}
assert(hcnt<150);
double res=4e9;
For(i,1,hcnt) For(j,i+1,hcnt){
res=min(res,dist(u,hh[i])+dist(u,hh[j])+dist(hh[i],hh[j]));
if(abs(res)<1e-8) { cout<<"0\n"; exit(0); }
}
if(res<ans){
debug("remake",_);
ans=res; O.clear(); tot=0;
For(i,1,_){
int v=tmp[i]; ll x0=X[v]/ans/2, y0=Y[v]/ans/2;
ll qwq=x0*ll(2e9)+y0;
int& o=O[qwq]; if(o==0) lcnt[o=++tot]=0;
// assert(lcnt[o]!=10);
lis[o][lcnt[o]++]=v;
}
}
else{
ll qwq=x*ll(2e9)+y;
int& o=O[qwq]; if(o==0) lcnt[o=++tot]=0;
lis[o][lcnt[o]++]=u;
}
}
// cout<<setprecision(10)<<fixed<<ans<<'\n';
static int kase=0;
cout<<"Case #"<<++kase<<": "<<setprecision(10)<<fixed<<ans<<'\n';
}
return 0;
}
// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// Started Coding On: April 11 Thu, 08 : 08 : 12
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
15 3 2 6 7 0 3 0 3 713 269 371 79 455 421 3 91983245 637281504 756917015 312173515 869576338 436726680 10000 14761642 78236002 9047458 47951098 5238002 27761162 476182 2523742 1428546 7571226 26190010 138805810 21904372 116092132 18094916 95902196 43332562 229660522 55237112 292754072 52380020 27761...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
15 3 501691275 344354353 167768963 536043860 249445040 557426549 4 1000000000 0 0 0 1000000000 1000000000 0 1000000000 1000000 138925776 669369648 61257680 295150640 170762328 822763944 55483472 267329456 97736936 470914328 84041848 404928904 18463588 88960924 124429360 599523280 95066048 458045504 ...