codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述
之前几乎没写过什么这种几何的计算题。在众多大佬的博客下终于记起来了当时的公式。嘚赶快补计算几何和概率论的坑了。。。
这题的要求,在对两圆相交的板子略做修改后,很容易实现。这里直接给出代码。重点的部分有:两圆在相离(或外交)时输出第一个圆的面积、内涵(或内切)则需要分类讨论,是羊的圈大、还是狼的圈大。以下是代码:
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main()
{
double a,b,c,d,e,f,jiao1,jiao2,s1,s2,s3,s4,l,py;
int t,s,j;
py=2*acos(0);
//cout<<py<<endl;
j=1;
cin>>t;
while(t--)
{
cin>>a>>b>>c;
cin>>d>>e>>f;
l=sqrt((d-a)*(d-a)+(e-b)*(e-b));//l是两圆的圆心距
if(l<=fabs(c-f))//如果内涵(切)
{
if(c>f)
{
cout<<"Case #"<<j++<<": ";
printf("%.11lf",py*(c*c-f*f));
cout<<endl;
}
else cout<<"Case #"<<j++<<": "<<"0"<<endl;
continue;
}
else if(l>=c+f)//如果相离(外切)
{
cout<<"Case #"<<j++<<": ";
printf("%.11lf",py*c*c);
cout<<endl;
continue;
}
//以下为一般的相交情况
jiao1=acos((l*l+c*c-f*f)/(2*l*c));//余弦定理求出第一个圆对应圆心角的一半
jiao2=acos((l*l+f*f-c*c)/(2*l*f));//同理求第二个圆
s1=jiao1*c*c;//第一个圆对应的扇形
s2=jiao2*f*f;//第二个圆对应扇形
s3=c*c*sin(jiao1)*cos(jiao1);//第一个圆心角对应的三角形
s4=f*f*sin(jiao2)*cos(jiao2);//第二个圆心角对应的三角形
cout<<"Case #"<<j++<<": ";
printf("%.11lf",py*c*c-(s1+s2-s3-s4));//输出第一个圆的面积减去公共部分面积
cout<<endl;
//cout<<s1+s2-s3-s4<<endl;
//在这里, s1+s2-s3-s4是圆的公共部分面积
}
}
圆心角对应的三角形可能会比较难理解,但只要画一个一般情况的图出来,模拟一边求解过程,就能更好的理解了。
写的时候,我还因为没讨论内切情况而WA2 ,感觉几何的情况要比其他题目的多得多啊。。
然后在这简述一下gym/100495/problem/E—Simple sequence的思路,这题也同样出现在了新生赛里。这题可以用类似尺取法的方式暴力。用两个元素l、r来标记当前段的前后位置,满足条件则尾部往后移动、不满足时就把头往后移动。在把头往后移动之前,需要讨论当前段的头是不是该区间的最大值或者最小追,若答案为是,则需要在移动后的区域里找到最大或最小值。这个暴力方法十分精妙,时间非常的逼近O(n)。很适合作为理解尺取法和区间取数的例题。
代码本来想打的。。但是刚要测试数据的时候Dev卡死了,然后就没了QAQ
codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述的更多相关文章
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
- Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]
题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- Codeforces 1089K - King Kog's Reception - [线段树][2018-2019 ICPC, NEERC, Northern Eurasia Finals Problem K]
题目链接:https://codeforces.com/contest/1089/problem/K time limit per test: 2 seconds memory limit per t ...
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题
Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...
- XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem K. Piecemaking
题目:Problem K. PiecemakingInput file: standard inputOutput file: standard outputTime limit: 1 secondM ...
- 2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...
随机推荐
- python API whoami
import getpass print getpass.getuser() See the documentation of the getpass module. getpass.getuser( ...
- Access无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开
使用SQL Server导入有密码的Access数据库内容,连接时出现错误提示: Access无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开 参考百度信息,可以点上图中的高级,在 ...
- Laravel-2
● php发邮件 参考:https://blog.csdn.net/sinat_37390744/article/details/54667794 ● ajax提交表单时防止csrf攻击 1. 在网页 ...
- 把vim改装为source sight
本文在ubuntu18.04上实践. 主要为VIM 安装4个插件: taglist,srcexpl,NERD_tree,ctrlp 1,taglist.vim :https://www.vim.org ...
- 分析servlet injection
@WebServlet("/cdiservlet") ||url映射 public class NewServlet extends HttpServlet { private M ...
- C++11 使用异步编程std::async和std::future
先说明一点:std::asyanc是std::future的高级封装, 一般我们不会直接使用std::futrue,而是使用对std::future的高级封装std::async. 下面分别说一下. ...
- etcd集群的搭建
由于最近在学习kubernetes,etcd作为kubernetes集群的主数据库,必须先启动. etcds实例名称 IP地址 Hostname etcd 1 192.168.142.161 kube ...
- php 与mysql 数据库
新手上路,php刚学,数据库刚学,花了两天终于读到数据库的数据了. 一路上的坎坷我在这里吐槽吐槽: <?php $mysql_server_name='localhost'; //改成自己的my ...
- java框架之SpringBoot(10)-启动流程及自定义starter
启动流程 直接从 SpringBoot 程序入口的 run 方法看起: public static ConfigurableApplicationContext run(Object source, ...
- Solr数据迁移
单机Solr部署在linux /opt目录下,运行一段时间后发现该目录分配的空间不足,而Solr的索引数据量较大,必须更改相关core下面的data目录,以改变索引存放的目录. 找到相应的solrco ...