Bzoj 1043 haoi2008 falling disc calculation ry

Source: Internet
Author: User

N discs fall in order to find the area of the final contour.

The primary disk is opposed! Let's unite! Drive away the primary disk!

Cough. Today I went to the topic solution and the white book to solve a very difficult question ......

First, we work backwards to process the disc falling behind each disc and its coverage interval. Then we can find a range and calculate the visible arc length of the disc.

Then there is the question of how to find the intersection part.

First, the two circles must intersection and then use atan2 to obtain the Polar Angle of the vector from the Center 1 to the Center 2, and then use the cosine theorem to find the angle between the two intersections and the center link. parts must be split into another Interval

It is not very troublesome to handle ...... All technologies♂Clever question

#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 1010#define PI 3.1415926536using namespace std;struct point{double x,y;};struct circle{point o;double r;}a[M];int n;double ans;pair<double,double>intervals[M<<1];int tot;inline double Distance(const point &p1,const point &p2){return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );}void Calculate(const circle o1,const circle o2,const double &dis){double alpha=atan2(o2.o.y-o1.o.y,o2.o.x-o1.o.x)+PI;double delta=acos((o1.r*o1.r+dis*dis-o2.r*o2.r)/(2*o1.r*dis));pair<double,double>temp(alpha-delta,alpha+delta);if(temp.first>=0&&temp.second<=2*PI)intervals[++tot]=temp;else if(temp.first<0)intervals[++tot]=make_pair(temp.first+2*PI,2*PI),intervals[++tot]=make_pair(0,temp.second);elseintervals[++tot]=make_pair(temp.first,2*PI),intervals[++tot]=make_pair(0,temp.second-2*PI);}double Interval_Union(){int i;double re=0,st=-1,ed=-1;sort(intervals+1,intervals+tot+1);for(i=1;i<=tot;i++){if(intervals[i].first>ed)re+=ed-st,st=intervals[i].first,ed=intervals[i].second;elseed=max(ed,intervals[i].second);}re+=ed-st;return 2*PI-re;}int main(){int i,j;cin>>n;for(i=n;i;i--)scanf("%lf%lf%lf",&a[i].r,&a[i].o.x,&a[i].o.y);for(i=1;i<=n;i++){tot=0;for(j=1;j<i;j++){double dis=Distance(a[i].o,a[j].o);if(a[j].r-a[i].r>dis)break;if(a[i].r+a[j].r>dis&&fabs(a[i].r-a[j].r)<dis)Calculate(a[i],a[j],dis);}if(j!=i)continue;ans+=Interval_Union()*a[i].r;}printf("%.3lf\n",ans);}


Bzoj 1043 haoi2008 falling disc calculation ry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.