SHOI 2014 全

来源:互联网 发布:windows nginx 下载 编辑:程序博客网 时间:2024/05/01 02:28

BZOJ 3564

        先顺时针转a度,再暴力三分套三分,光荣TLE,不过数据测应该还有80

        正解是最小圆覆盖

#include <cstdio>#include <cmath>#include <iostream>using namespace std;const int MAXN = 50001;const int INF = 1000000000;const double eps = 1e-6;const double pi = 3.14159265358979323;struct Point{double x,y;};typedef Point Vector;struct Line{Point p;Vector v;Line(Point _p,Vector _v):p(_p),v(_v){}};Point operator + (Point A,Point B){return (Point){A.x+B.x,A.y+B.y};}Point operator - (Point A,Point B){return (Point){A.x-B.x,A.y-B.y};}Point operator * (double k,Point A){return (Point){A.x*k,A.y*k};}double dot(Point A,Point B){return A.x*B.x+A.y*B.y;};double cross(Point A,Point B){return A.x*B.y-A.y*B.x;}int n;double a,p,ans;Point P[MAXN];Point Center;double r;Point LineInsection(Line A,Line B){Point P = A.p, Q = B.p;Vector v = A.v, w = B.v;Vector u = P-Q;double t = cross(w,u)/cross(v,w);return P+t*v; }inline void rotate(Point &P,double a){a = a*pi/180;double ang = atan2(P.y,P.x);ang += a;double len = sqrt(dot(P,P));P.x = len*cos(ang);P.y = len*sin(ang);}/*double get_max(Point vec){double _max = -INF;for (int i=1;i<=n;i++){double x0 = P[i].x-vec.x;double y0 = P[i].y-vec.y;_max = max(_max,(x0*x0+p*p*y0*y0)/(p*p));}return _max;}double calc(double x,double &y){double l = -INF, r = INF;while (r-l > eps){double mid_l = l+(r-l)/3;double mid_r = r-(r-l)/3;if (get_max((Point){x,mid_l}) > get_max((Point){x,mid_r})) l = mid_l;else r = mid_r;}y = l;return get_max((Point){x,l});}Point trisearch(){double L = -INF, R = INF;double y;while (R-L > eps){double MID_L = L+(R-L)/3;double MID_R = R-(R-L)/3;if (calc(MID_L,y) > calc(MID_R,y)) L = MID_L;else R = MID_R;}calc(L,y);return (Point){L,y};}*/inline double dist(Point A,Point B){return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}Point Get_Center(Point p,Point q,Point r){Vector VA = q-p;swap(VA.x,VA.y);VA.x = -VA.x;Point PA = 0.5*(p+q);Line A = (Line){PA,VA};Vector VB = q-r;swap(VB.x,VB.y);VB.x = -VB.x;Point PB = 0.5*(q+r);Line B = (Line){PB,VB};return LineInsection(A,B);}void FindMinCircle(){Center = P[1];for (int i=1;i<=n;i++) if (dist(P[i],Center) > r+eps){Center = P[i];r = 0;for (int j=1;j<i;j++) if (dist(P[j],Center) > r+eps){Center = 0.5*(P[i]+P[j]);r = dist(P[i],P[j])/2;for (int k=1;k<j;k++) if (dist(P[k],Center) > r+eps){Center = Get_Center(P[i],P[j],P[k]);r = dist(P[i],Center);}}}}int main(){scanf("%d",&n);if (n == 1){printf("0.000");return 0;}for (int i=1;i<=n;i++) scanf("%lf%lf",&P[i].x,&P[i].y);scanf("%lf%lf",&a,&p);for (int i=1;i<=n;i++) rotate(P[i],-a);for (int i=1;i<=n;i++) P[i].x = P[i].x/p;FindMinCircle();printf("%.3lf",r);return 0;}


BZOJ 3565

        嗯没有搞懂逆元有什么意义,直接暴力树状数组

BZOJ 3566

       很简单的一个树形dp,我脑残概率都是加上的……

#include <cstdio>#include <cmath>#include <algorithm>#include <vector>using namespace std;const int MAXN = 500001;const double eps = 1e-7;struct Node{int v;double per;Node(int _v,double _per):v(_v),per(_per){};};int n;double p[MAXN];double dp[MAXN];double direct[MAXN];double ans;vector <Node> G[MAXN];void dfs(int u,int fa){p[u] = direct[u]/100.0;for (int i=0;i<G[u].size();i++){int v = G[u][i].v;if (v != fa){dfs(v,u);p[u] += p[v]*G[u][i].per-p[u]*p[v]*G[u][i].per;}}}double down(int u,int fa){ans += dp[u];for (int i=0;i<G[u].size();i++){int v = G[u][i].v;if (v != fa){double temp = 1-p[v]*G[u][i].per;          if(temp < eps) dp[v]=1.0;          else          {              double y = (dp[u]-p[v]*G[u][i].per)/temp;              dp[v] =p[v]+y*G[u][i].per-p[v]*y*G[u][i].per;          }          down(v,u);  }}}int main(){scanf("%d",&n);for (int i=1;i<n;i++){int u,v,per;scanf("%d%d%d",&u,&v,&per);G[u].push_back((Node){v,per/100.0});G[v].push_back((Node){u,per/100.0});}for (int i=1;i<=n;i++) scanf("%lf",&direct[i]);dfs(1,0);dp[1] = p[1];down(1,0);printf("%lf\n",ans);return 0;}


0 0
原创粉丝点击