题意:x=[-200,200],y=[-200,200]的平面,一天中太阳从不同角度射到长椅(原点(0,0))上,有一些树(用圆表示),问哪个时刻(分钟为单位)太阳光线与这些圆所交的弦长总和最长。太阳距离原点总是500m。(这些圆不会互相相交,每个圆都不包括原点或者不经过原点

解法:直接暴力24*60分钟,找出此时的角度,然后求出直线方程,再枚举每个圆,求出弦长。注意这里每个圆都不包括原点,所以直线与圆的交点一定在同一侧,所以。。我当时想多了,没看清题目。把他当成可以包含原点了,代码超长,幸好过了。

代码:

没想多应该这样就可以了:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#define INint 2147483647
#define pi acos(-1.0)
#define eps 1e-4
using namespace std;
#define N 100102
#define M 22 typedef struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
}Vector; double DegtoRad(double deg)
{
return deg/180.0*pi;
} int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (point A,point B){return Vector(A.x-B.x,A.y-B.y); }
Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}
bool operator == (const point& a,const point& b){return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;}
bool operator < (const point& a,const point& b){return a.x<b.x ||(a.x==b.x&&a.y<b.y);}
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;} //叉积 ,大于零说明B在A的左边。小于零说明B在A的右边
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;} //点积
double length(Vector A){return sqrt(Dot(A,A));} //向量长度 double DistanceToSegment(point P,point A,point B)
{
if(A==B) return length(P-A);
Vector v1=B-A,v2=P-A,v3=P-B;
if(dcmp(Dot(v1,v2))<) return length(v2);
else if(dcmp(Dot(v1,v3))>) return length(v3);
else return fabs(Cross(v1,v2))/length(v1);
} point p[];
double ra[]; int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF && n)
{
for(i=;i<n;i++)
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&ra[i]);
double maxi = 0.0;
int S = *;
for(i=;i<S;i++)
{
point A,B,C;
A = point(0.0,0.0);
double rad = DegtoRad(i/4.0);
B = point(*sin(rad),*cos(rad));
double sum = 0.0;
for(j=;j<n;j++)
{
C = p[j];
double dis = DistanceToSegment(C,A,B);
if(dis >= ra[j])
continue;
sum += 2.0*sqrt(ra[j]*ra[j]-dis*dis);
}
maxi = max(maxi,sum);
}
printf("%.3lf\n",maxi);
}
return ;
}

当时的代码(考虑了可能包含原点):

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#define pi acos(-1.0)
using namespace std;
#define N 100102
#define M 22 struct node
{
double x,y,r;
}p[]; int getPlane(double nx,double ny)
{
if(nx > && ny > )
return ;
else if(nx > && ny < )
return ;
else if(nx < && ny < )
return ;
else if(nx < && ny > )
return ;
else
return ;
} double dis(int nx,int ny)
{
return sqrt(nx*nx + ny*ny);
} int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF && n)
{
for(i=;i<n;i++)
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
int S = *;
double Si = 24.0*60.0;
int Plane;
double maxi = 0.0;
for(i=;i<S;i++)
{
if(i == || i == || i == || i == )
continue;
double A = tan(*pi*(double)i/Si);
double B = -1.0;
double k = A;
double di = sqrt(A*A+B*B);
if(i > && i < )
Plane = ;
else if(i > && i < )
Plane = ;
else if(i > && i < )
Plane = ;
else
Plane = ;
double sum = 0.0;
for(j=;j<n;j++)
{
double x = p[j].x;
double y = p[j].y;
double r = p[j].r;
double PtoL = fabs(A*x-y)/di;
if(PtoL > r)
continue;
double AA = k*k+1.0;
double BB = -(2.0*x+2.0*k*y);
double CC = x*x + y*y - r*r;
if(BB*BB-4.0*AA*CC <= 0.0)
continue;
double jie1x = (-BB+sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie1y = k*jie1x;
double jie2x = (-BB-sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie2y = k*jie2x;
int P1 = getPlane(jie1x,jie1y);
int P2 = getPlane(jie2x,jie2y);
if(P1 == Plane && P2 == Plane)
sum += 2.0*sqrt(r*r-PtoL*PtoL);
else if(P1 == Plane)
sum += dis(jie1x,jie1y);
else if(P2 == Plane)
sum += dis(jie2x,jie2y);
}
maxi = max(maxi,sum);
}
//up
double sum = 0.0;
for(j=;j<n;j++)
{
double x = p[j].x;
double y = p[j].y;
double r = p[j].r;
double PtoL = x;
if(PtoL > r)
continue;
double AA = 1.0;
double BB = -2.0*y;
double CC = x*x + y*y - r*r;
double jie1x = 0.0;
double jie1y = (-BB+sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie2x = 0.0;
double jie2y = (-BB-sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
if(jie1y > && jie2y > )
sum += fabs(jie1y-jie2y);
else if(jie1y > )
sum += jie1y;
else if(jie2y > )
sum += jie2y;
}
maxi = max(maxi,sum);
//down
sum = 0.0;
for(j=;j<n;j++)
{
double x = p[j].x;
double y = p[j].y;
double r = p[j].r;
double PtoL = x;
if(PtoL > r)
continue;
double AA = 1.0;
double BB = -2.0*y;
double CC = x*x + y*y - r*r;
double jie1x = 0.0;
double jie1y = (-BB+sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie2x = 0.0;
double jie2y = (-BB-sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
if(jie1y < && jie2y < )
sum += fabs(jie1y-jie2y);
else if(jie1y < )
sum += -jie1y;
else if(jie2y < )
sum += -jie2y;
}
maxi = max(maxi,sum);
//right
sum = 0.0;
for(j=;j<n;j++)
{
double x = p[j].x;
double y = p[j].y;
double r = p[j].r;
double PtoL = y;
if(PtoL > r)
continue;
double AA = 1.0;
double BB = -2.0*x;
double CC = x*x + y*y - r*r;
double jie1x = (-BB+sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie1y = 0.0;
double jie2x = (-BB-sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie2y = 0.0;
if(jie1x > && jie2x > )
sum += fabs(jie1x-jie2x);
else if(jie1x > )
sum += jie1x;
else if(jie2x > )
sum += jie2x;
}
maxi = max(maxi,sum);
//left
sum = 0.0;
for(j=;j<n;j++)
{
double x = p[j].x;
double y = p[j].y;
double r = p[j].r;
double PtoL = y;
if(PtoL > r)
continue;
double AA = 1.0;
double BB = -2.0*x;
double CC = x*x + y*y - r*r;
double jie1x = (-BB+sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie1y = 0.0;
double jie2x = (-BB-sqrt(BB*BB-4.0*AA*CC))/(2.0*AA);
double jie2y = 0.0;
if(jie1x < && jie2x < )
sum += fabs(jie1x-jie2x);
else if(jie1x < )
sum += -jie1x;
else if(jie2x < )
sum += -jie2x;
}
maxi = max(maxi,sum);
printf("%.3lf\n",maxi);
}
return ;
}

UVALive 6092 Catching Shade in Flatland --枚举+几何计算的更多相关文章

  1. UVALive - 3263 That Nice Euler Circuit (几何)

    UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit 题意:  给 ...

  2. 1549: Navigition Problem (几何计算+模拟 细节较多)

    1549: Navigition Problem Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 256 Mb     Su ...

  3. Jack Straws POJ - 1127 (几何计算)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5428   Accepted: 2461 Descr ...

  4. UVALive 6885 Flowery Trails 最短路枚举

    题目连接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=129723 题意: 给你一个n点m图的边 1到n有多条最短路 ...

  5. fzu 2035 Axial symmetry(枚举+几何)

    题目链接:fzu 2035 Axial symmetry 题目大意:给出n个点,表示n边形的n个顶点,判断该n边形是否为轴对称图形.(给出点按照图形的顺时针或逆时针给出. 解题思路:将相邻两个点的中点 ...

  6. UVALive 6692 Lucky Number (思路 + 枚举)

    题意:给你n 个数字,某一个数的幸运数是这个数前面比他小 离他最远的位置之差,求出最大幸运值. 析:先按从大到小排序,然后去维护那个最大的id,一直比较,更新最大值就好. 代码如下: #pragma ...

  7. Direct2D 几何计算和几何变幻

    D2D不仅可以绘制,还可以对多个几何图形对象进行空间运算.这功能应该在GIS界比较吃香. 这些计算包括: 合并几何对象,可以设置求交还是求并,CombineWithGeometry 边界,加宽边界,查 ...

  8. Codeforces 552E Vanya and Brackets(枚举 + 表达式计算)

    题目链接 Vanya and Brackets 题目大意是给出一个只由1-9的数.乘号和加号组成的表达式,若要在这个表达式中加上一对括号,求加上括号的表达式的最大值. 我们发现,左括号的位置肯定是最左 ...

  9. Jack Straws POJ - 1127 (简单几何计算 + 并查集)

    In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...

随机推荐

  1. 配置ssh免密码连接

    建立ssh连接步骤: 1,在主机安装ssh-server,执行指令: apt-get install openssh-server 2,在主机上执行指令: netstat -atpn | grep 可 ...

  2. Python迭代器:捕获Generator的返回值

    但是用for循环调用generator时,发现拿不到generator的return语句的返回值.如果想要拿到返回值,必须捕获StopIteration错误,返回值包含在StopIteration的v ...

  3. ArcEngine尝试读取或写入受保护的内存

    先说一下我的开发环境: Win10 + ArcGIS10.0 + ArcEngine10.0 + Framework4.0 今天调用新的GP工具则出现"尝试读取或写入受保护的内存.这通常指示 ...

  4. SharePoint 2013 跨网站集发布功能简介

    在SharePoint Server 2013网站实施中,我们经常会遇到跨网站集获取数据,而2013的这一跨网站集发布功能,正好满足我们这样的需求. 使用SharePoint 2013中的跨网站发布, ...

  5. Lync 客户端:无法登陆到Lync,验证服务器中的证书时遇到问题

    安装完Lync客户端后,运行时Lync客户端时,报出如下错误: [原因解析] Lync客户端没有正确安装CA证书链. [解决办法] 第一种方法:将计算机加入域. 第二种方法:不加入域的处理方法: 1. ...

  6. How to Get SharePoint Client Context in SharePoint Apps (Provider Hosted / SharePoint Access ) in CSOM (Client Side Object Model)

    http://www.codeproject.com/Articles/581060/HowplustoplusGetplusSharePointplusClientplusContex Downlo ...

  7. 安装和配置tomcat服务器

    本文主要介绍一下tomcat服务器的安装和配置 1.获取tomcat tomcat服务器可以到它的官方网站(http://tomcat.apache.org)上下载 2.安装tomcat 具体步骤: ...

  8. 《C程序设计的抽象思维》2.10编程练习(未完)

    本文地址:http://www.cnblogs.com/archimedes/p/programming-abstractions-in-c-2.html,转载请注明源地址. 2.按照规定求圆柱的表面 ...

  9. 异步get请求之代理方法

    #import "ViewController.h" #import "Header.h" @interface ViewController ()<NS ...

  10. IOS 登陆界面的简单编写(通过NSNotificationCenter)

    在介绍内容的之前,先看一下实现结果. 通过细节可以发现,只有当手机号与密码都输入的情况登录按钮才会变亮.那么这是怎么实现的呢? 首先我们要知道,这种情况的发生的首要条件便是每时每刻都知道两个TextF ...