光纤
《不想调了》
《再草一遍😡》,似乎是炸int128了,有巨佬感兴趣可以调一调。
真是思慕😡,重构了一遍分数更低了😡。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int __int128
const int N=1e6+10;
inline int read(){
int ans=0;char ch=getchar_unlocked();bool fl=0;
while(ch<'0'||ch>'9'){if(ch=='-')fl=1;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar_unlocked();
return fl?(~ans+1):ans;
}
void print(int x){
if(x<0)putchar_unlocked('-'),x=-x;
if(x>9)print(x/10);
putchar_unlocked(x%10|48);
}
inline int absl(int x){return x>0?x:-x;}
inline int min(int x,int y){return x<y?x:y;}
struct rea{
int mu,zi;
rea jian(){
int gcd=__gcd(absl(zi),absl(mu));
if(mu<0){mu*=-1;zi*=-1;}
if(!zi){mu=1;return *this;}
if(!gcd)return *this;
zi/=gcd;mu/=gcd;
return *this;
}
rea(int x=0,int y=1){zi=x,mu=y;jian();}
rea dao(){return rea(mu,zi);}
rea operator+(rea a){return (rea(zi*a.mu+mu*a.zi,mu*a.mu)).jian();}
rea operator*(rea a){
int gcd1=__gcd(zi,a.mu);
int gcd2=__gcd(a.zi,mu);
return (rea((zi/gcd1)*(a.zi/gcd2),(mu/gcd2)*(a.mu/gcd1))).jian();
}
rea operator/(rea a){return (*this*a.dao()).jian();}
rea operator-(){return rea(-zi,mu);}
rea operator-(rea a){return *this+(-a);}
bool operator<(rea a){return zi*a.mu<a.zi*mu;}
bool operator>(rea a){return !(*this<a);}
bool operator==(rea a){return !((*this<a)||(*this>a));}
void out(){
jian();
print(zi),putchar_unlocked('/');
print(mu);putchar_unlocked('\n');
}
};
rea minrea(rea x,rea y){return x<y?x:y;}
struct vec{
int x,y;
int operator*(const vec a)const{return x*a.y-y*a.x;}
vec operator-(const vec a)const{return (vec){x-a.x,y-a.y};}
// bool operator<(const vec a)const{return (x^a.x)?x<a.x:y<a.y;}
int mo(){
if(x*x+y*y<0){
putchar_unlocked('!');
exit(0);
}
return x*x+y*y;
}
void out(){
print(x);putchar_unlocked(' ');
print(y);putchar_unlocked('\n');
}
}s[N],h[N];
bool vis[N];
int n,top,stk[N],ans;
bool cmp(vec a,vec b){return (a.x^b.x)?a.x<b.x:a.y<b.y;}
void prework(){
n=read();
for(int i=1;i<=n;i++){
s[i].x=read(),s[i].y=read();
}sort(s+1,s+1+n,cmp);
stk[++top]=1;
for(int i=1;i<=n;i++){
while(top>=2&&
(s[stk[top]]-s[stk[top-1]])*(s[i]-s[stk[top]])<=0)
vis[stk[top--]]=0;
vis[i]=1;
stk[++top]=i;
}
int tmp=top;
for(int i=n-1;i;i--){
if(!vis[i]){
while(top>tmp&&(s[stk[top]]-s[stk[top-1]])*(s[i]-s[stk[top]])<=0)
vis[stk[top--]]=0;
vis[i]=1;
stk[++top]=i;
}
}
for(int i=1;i<=top;i++)h[i]=s[stk[i]];
}
rea get_dis(vec x,vec y,vec z){
vec a=y-x,b=z-x;
int m=a.mo(),l=(a*b),gcd=__gcd(l,m);
m/=gcd,l/=gcd;
if(l*l*gcd<0){
putchar_unlocked('!');
exit(0);
}
return (rea(l*l*gcd,m)).jian();
}
inline int hu(int x){
return (x%(top-1))?(x%(top-1)):(top-1);
}
signed main(){
// freopen("ex_A3.in","r",stdin);
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
prework();
int l=2;
rea ans((__int128)1000000000000000000*(__int128)1000000000000000,1);
for(int i=1;i<top;i++){
while(get_dis(h[i],h[hu(i+1)],h[hu(l)])<get_dis(h[i],h[hu(i+1)],h[hu(l+1)]))l++;
ans=minrea(ans,get_dis(h[i],h[hu(i+1)],h[hu(l)]));
}
if(ans.zi==(__int128)1000000000000000000*(__int128)1000000000000000)ans=0;
ans=ans*rea(1,4);
ans.out();
}
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int __int128
#define pd putchar_unlocked(' ')
#define endl putchar_unlocked('\n')
#define chu putchar_unlocked('/')
const int N=1e6+10;
inline int absl(int x){return x<0?-x:x;}
inline int read(){
int ans=0;char ch=getchar_unlocked();bool fl=0;
while(ch<'0'||ch>'9'){if(ch=='-')fl=1;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar_unlocked();
return fl?(~ans+1):ans;
}
void print(int x){
if(x<0)putchar_unlocked('-'),x=-x;
if(x>9)print(x/10);
putchar_unlocked(x%10|48);
}
struct frac{
int z,m;
frac(int x=0,int y=1){z=x,m=y;}
frac jian(){
int gcd=__gcd(absl(z),absl(m));
z/=gcd,m/=gcd;
return *this;
}
frac operator+(frac a){return (frac(z*a.m+m*a.z,m*a.m)).jian();}
frac operator-(){return frac(-z,m);}
frac operator-(frac a){return (*this+(-a)).jian();}
frac operator*(frac a){
int gcd1=__gcd(absl(z),absl(a.m)),gcd2=__gcd(absl(m),absl(a.z));
frac ans=frac((z/gcd1)*(a.z/gcd2),(m/gcd2)*(a.m/gcd1));
return ans.jian();
}
frac dao(){return frac(m,z);}
frac operator/(frac a){return (*this*a.dao()).jian();}
long double it(){return z*1.0/m;}
bool operator<(frac a){return ((*this).it())<a.it();}
bool operator<=(frac a){return ((*this).it())<=a.it();}
void out(){
print(z);chu;
print(m);endl;
}
};
struct vec{
int x,y;
vec(int a=0,int b=0){x=a,y=b;}
vec operator+(vec a){return vec(x+a.x,y+a.y);}
vec operator-(){return vec(-x,-y);}
vec operator-(vec a){return *this+(-a);}
int operator*(vec a){return x*a.y-y*a.x;}
int mo(){return x*x+y*y;}
void out(){print(x);pd;print(y);endl;}
}s[N],h[N];
bool cmp(vec a,vec b){return (a.x^b.x)?a.x<b.x:a.y<b.y;}
int n,stk[N],top;
bool vis[N];
void prework(){
n=read();
for(int i=1;i<=n;i++){
s[i].x=read();
s[i].y=read();
}sort(s+1,s+1+n,cmp);
stk[++top]=1;
for(int i=2;i<=n;i++){
while(top>=2&&(s[stk[top]]-s[stk[top-1]])*(s[i]-s[stk[top]])<=0)vis[stk[top--]]=0;
vis[i]=1;stk[++top]=i;
}int tmp=top;
for(int i=n-1;i>0;i--){
if(!vis[i]){
while(top>tmp&&(s[stk[top]]-stk[top-1])*(s[i]-s[stk[top]])<=0)vis[stk[top--]]=0;
vis[i]=1;stk[++top]=i;
}
}
for(int i=1;i<=top;i++)h[i]=s[stk[i]];
}
frac get_d(vec x,vec y,vec z){
vec a=y-x,b=z-x;
int op=absl(a*b),mod=a.mo(),gcd=__gcd(op,mod);
op/=gcd,mod/=gcd;
return (frac(op*op*gcd,mod)).jian();
}
inline int hu(int x){return x%(top-1)?(x%(top-1)):(top-1);}
signed main(){
// freopen("1.in","r",stdin);
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
prework();
if(n==2)frac(0,1).out(),exit(0);
int l=2;frac ans;
for(int i=1;i<top;i++){
while(get_d(h[i],h[i+1],h[hu(l)])<get_d(h[i],h[i+1],h[hu(l+1)]))l++;
frac a;
a=get_d(h[i],h[i+1],h[hu(l)]);
if(a<ans||(ans.z==0))ans=a;
}
frac op;op=frac(1,4);
(ans*op).out();
}
终于改出来了,哈哈哈!!!!!!!!!!!!!!
爽
点击查看代码
#define yhl yhl
#include<bits/stdc++.h>
using namespace std;
#define int __int128
#define pd putchar_unlocked(' ')
#define endl putchar_unlocked('\n')
#define chu putchar_unlocked('/')
const int N=1e6+10;
inline int absl(int x){return x<yhl?-x:x;}
inline int read(){
int ans=yhl;char ch=getchar_unlocked();bool fl=yhl;
while(ch<'0'||ch>'9'){if(ch=='-')fl=1;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar_unlocked();
return fl?(~ans+1):ans;
}
void print(int x){
if(x<yhl)putchar_unlocked('-'),x=-x;
if(x>9)print(x/10);
putchar_unlocked(x%10|48);
}
struct frac{
int z,m;
frac(int x=yhl,int y=1){z=x,m=y;}
frac jian(){
int gcd=__gcd(absl(z),absl(m));
z/=gcd,m/=gcd;
return *this;
}
frac operator+(frac a){return (frac(z*a.m+m*a.z,m*a.m)).jian();}
frac operator-(){return frac(-z,m);}
frac operator-(frac a){return (*this+(-a)).jian();}
frac operator*(frac a){
int gcd1=__gcd(absl(z),absl(a.m)),gcd2=__gcd(absl(m),absl(a.z));
frac ans=frac((z/gcd1)*(a.z/gcd2),(m/gcd2)*(a.m/gcd1));
return ans.jian();
}
frac dao(){return frac(m,z);}
frac operator/(frac a){return (*this*a.dao()).jian();}
long double it(){return z*1.yhl/m;}
bool operator<(frac a){return ((*this).it())<a.it();}
bool operator<=(frac a){return ((*this).it())<=a.it();}
void out(){
print(z);chu;
print(m);endl;
}
};
struct vec{
int x,y;
vec(int a=yhl,int b=yhl){x=a,y=b;}
vec operator+(vec a){return vec(x+a.x,y+a.y);}
vec operator-(){return vec(-x,-y);}
vec operator-(vec a){return *this+(-a);}
int operator*(vec a){return x*a.y-y*a.x;}
int mo(){return x*x+y*y;}
void out(){print(x);pd;print(y);endl;}
}s[N],h[N];
bool cmp(vec a,vec b){return (a.x^b.x)?a.x<b.x:a.y<b.y;}
int n,stk[N],top;
bool vis[N];
void prework(){
n=read();
for(int i=1;i<=n;i++){
s[i].x=read();
s[i].y=read();
}sort(s+1,s+1+n,cmp);
stk[++top]=1;
for(int i=2;i<=n;i++){
while(top>=2&&(s[stk[top]]-s[stk[top-1]])*(s[i]-s[stk[top]])<=yhl)vis[stk[top--]]=yhl;
vis[i]=1;stk[++top]=i;
}int tmp=top;
for(int i=n-1;i>yhl;i--){
if(!vis[i]){
while(top>tmp&&(s[stk[top]]-s[stk[top-1]])*(s[i]-s[stk[top]])<=yhl)vis[stk[top--]]=yhl;
vis[i]=1;stk[++top]=i;
}
}
for(int i=1;i<=top;i++)h[i]=s[stk[i]];
}
frac get_d(vec x,vec y,vec z){
vec a=y-x,b=z-x;
int op=absl(a*b),mod=a.mo(),gcd=__gcd(op,mod);
op/=gcd,mod/=gcd;
return (frac(op*op*gcd,mod)).jian();
}
inline int hu(int x){return x%(top-1)?(x%(top-1)):(top-1);}
signed main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
prework();
int l=2;
frac ans(yhl,1);
for(int i=1;i<top;i++){
while(get_d(h[i],h[hu(i+1)],h[hu(l)])<get_d(h[i],h[hu(i+1)],h[hu(l+1)]))l++;
frac a(yhl,1);a=get_d(h[i],h[hu(i+1)],h[hu(l)]);
if(ans.z==yhl||a<ans)ans=a;
}
ans=ans*frac(1,4);
ans.out();
return yhl;
}
糖完了,把
s[stk[top]]-s[dtk[top-1]]
写成了
s[stk[top]]-stk[top-1]
《关键是这堂食东西还拿了30》