博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
「SDOI2018」物理实验
阅读量:4516 次
发布时间:2019-06-08

本文共 3841 字,大约阅读时间需要 12 分钟。

题目大意:

  这题不好描述,直接看吧……

题解:

  很无脑的题……就是卡精度+难写。代码能力还是太差了。

  其实可以直接用long double肝过去。但我的代码似乎太丑了,以至于跑得奇慢无比。

代码:

  

#include "bits/stdc++.h"using namespace std;inline int read() {    int s=0,k=1;char ch=getchar();    while (ch<'0'|ch>'9') ch=='-'?k=-1:0,ch=getchar();    while (ch>47&ch<='9') s=s*10+(ch^48),ch=getchar();    return s*k;}#define double long double const double eps=1e-10;const int N=1e4+10;inline int dcmp(double a) {    if (a>eps) return 1;    if (a<-eps) return -1;    return 0; }struct P{    P(double _x=0.0,double _y=0.0):x(_x),y(_y){}    double x,y;    double &operator [] (int k) {return k?y:x;}    friend bool operator <(P a,P b) {        return dcmp(a[0]-b[0])==-1||(dcmp(a[0]-b[0])==0&&dcmp(a[1]-b[1])==-1);    }    friend double operator *(P a,P b) {        return a[0]*b[1]-b[0]*a[1];    }    friend P operator /(P a,double b) {        return P(a[0]/b,a[1]/b);    }    friend P operator + (P a,P b) {        return P(a[0]+b[0],a[1]+b[1]);    }    friend P operator * (P a,double b) {        return P(a[0]*b,a[1]*b);    }    friend double operator /(P a,P b) {        return a[0]*b[0]+b[1]*a[1];    }    inline double leth(){        return sqrt(x*x+y*y);    }};P operator -(P a,P b) {    return P(a[0]-b[0],a[1]-b[1]);}    struct L{    L(){}L(P _a,P _b):a(_a),b(_b),c(_b-_a),slope(atan2((a-b)[1],(a-b)[0])){}    P a,b,c;double slope;    P &operator[] (int k) {        if(!k) return a;        if (k==1) return b;        return c;    }    friend double touying (L x,L y) {        return x[2]/y[2]/(x[2].leth());    }    friend double touying (L x,P y) {        return x[2]/(y-x[0])/(x[2].leth());    }    friend bool operator <(L x,L y) {        double pos = max (x[0][0],y[0][0]);        return dcmp(fabs(x[0][1] + x[2][1] * (pos-x[0][0]) / ( x[1][0] - x[0][0] )) -                   fabs(y[0][1] + y[2][1] * (pos-y[0][0]) / ( y[1][0] - y[0][0] )) ) == -1;                      }}block[N],gui;inline bool Judge(L a,L b) {    return dcmp(b[2]*(a[0]-b[0]))==1;}inline double dis(P p,L l) {    return l[2]*(p-l[0])/l[2].leth();}double lft[N],lth[N],rght[N],rth[N];int n,leth,m;int pl[N],pr[N];struct node {    P pos;int id;    friend bool operator <(node a,node b) {        return a.pos
up,down;double res[N*6];inline double calc (double x2,double x1,L l) { P delta=l[2]*(x2-x1)/l[2][0]; return delta.leth();}int main(){ int T=read(); register int i,j; while (T-- ) { n=read(); for (i=1;i<=n;++i) { double x1=read(),y1=read(),x2=read(),y2=read(); if (x1>x2) swap(x1,x2),swap(y1,y2); if (x1==x2&&y1>y2) swap(y1,y2); block[i]=L(P(x1,y1),P(x2,y2)); } double x1=read(),y1=read(),x2=read(),y2=read();leth=read(); if (x1>x2) swap(x1,x2),swap(y1,y2); if (x1==x2&&y1>y2) swap(y1,y2); gui=L(P(x1,y1),P(x2,y2)); m=0; for (i=1;i<=n;++i) { P a=block[i][0],b=block[i][1]; P na,nb; na[0] = touying(gui,a),na[1] = dis(a,gui); nb[0] = touying(gui,b),nb[1] = dis(b,gui); if (nb
0){ if (block[np[j].id][0][1]<-eps) down.insert(block[np[j].id]); else up.insert(block[np[j].id]); } ++j; res[j]=0.0; if (up.size()){ tmp = calc (np[j].pos[0],np[j-1].pos[0],*up.begin()); res[j] +=tmp; } if (down.size()) { tmp = calc (np[j].pos[0],np[j-1].pos[0],*down.begin()); res[j] +=tmp; } } for (i=j=1;i<=6*n&&j<=6*n;++i,ans-=res[i]) { while (j<=6*n&&dcmp(np[j].pos[0]-np[i].pos[0]-leth)<=0) ans+=res[j++]; ret=max(ret,ans); } printf("%.15Lf\n",ret); }}

  

转载于:https://www.cnblogs.com/Troywar/p/9061613.html

你可能感兴趣的文章
MySQL 引擎 和 InnoDB并发控制 简介
查看>>
Dave Python 练习二
查看>>
Integer类之成员变量
查看>>
菜根谭#179
查看>>
如何获取多个字符串中最长的共同子字符串?
查看>>
Android 开发笔记___textvieww__跑马灯效果
查看>>
[ JS 进阶 ] 闭包,作用域链,垃圾回收,内存泄露
查看>>
GitHub注册与Git安装
查看>>
ThinkPHP 更新数据 save方法
查看>>
Bshare自定义分享按钮
查看>>
11Qt样式表
查看>>
轮询/长轮询
查看>>
IOS开发-懒加载\延迟加载-图片浏览器实例
查看>>
何从之
查看>>
[Ext JS 4] contentEL,renderTo, applyTo 释义与区别
查看>>
数据盘【小蒙淘金】4.24金评-黄金白银行情分析及部分操作建议-java教程
查看>>
线段树单点更新+反素数 poj-2886-Who Gets the Most Candies
查看>>
iphone的app图标知识
查看>>
网易云信自定义消息(类似微信分享界面)
查看>>
whose view is not in the window hierarchy
查看>>