UVALive 3716 DNA Regions ——(扫描法)
乍一看这个问题似乎是很复杂,但其实很好解决。
先处理出每个点到原点的距离和到x正半轴的角度(从x正半轴逆时针旋转的角度)。然后以后者进行排序。
枚举每一个点到圆心的距离,作为半径,并找出其他到圆心距离不超过这个值的点,由于他们的角度是有序的,因此线性的找出角度差最小的满足题意的两个点即可(相当于拿一个长度为k的尺子不断地移动过去)。
那么总的复杂度为O(n^2)。
代码如下(注意atan2的用法):
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
const int N = + ;
const double pi = acos(-); int n,k;
struct node
{
int x, y;
double angle, dis;
void get()
{
double t = x * x + y * y;
//dis = sqrt(t);
dis = t; angle = atan2(1.0*y, 1.0*x);
/*if(y >= 0)
{
if(x >= 0)
{
angle = asin(1.0*y / dis);
}
else
{
angle = pi - asin(1.0*y / dis);
}
}
else
{
if(x >= 0) angle = 2.0 * pi - asin(1.0*y / dis);
else angle = pi + asin(1.0*y / dis);
}*/
}
bool operator < (const node & t) const
{
if(fabs(angle - t.angle) < 1e-)
{
return dis < t.dis;
}
return angle < t.angle;
}
}p[N]; double q[N*]; int main()
{
int kase = ;
while(scanf("%d%d",&n,&k) == )
{
if(n == && k == ) break;
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].get();
}
sort(p+,p++n); if(k == ) {printf("Case #%d: 0.00\n",kase++); continue;} double ans = 1e10;
for(int i=;i<=n;i++)
{
double r = p[i].dis;
int num = ;
for(int j=;j<=n;j++)
{
if(p[j].dis <= r) q[++num] = p[j].angle;
}
if(num < k) continue;
for(int j=;j<=num;j++)
{
q[j+num] = *pi + q[j];
}
for(int j=;j<=num;j++)
{
ans = min(ans, r * (q[j+k-] - q[j]) / 2.0);
}
}
printf("Case #%d: %.2f\n",kase++,ans);
}
return ;
}
UVALive 3716 DNA Regions ——(扫描法)的更多相关文章
- UVALive 3716 DNA Regions
题目大意:给定两个长度相等的字符串A和B,与一个百分比p%,求最长的.失配不超过p%的区间长度.O(nlogn). 题目比较简单套路,推推式子就好了. 记S[i]表示到下标i一共有多少个失配,就相当于 ...
- UVALive 3716 DNA Regions ——(式子变形)
一开始直接想到了二分,写了一发然后过了全部样例就交了,果断WA.因为这个问题显然是不满足单调性的. 然后想之前刚做的斜率优化DP,但是那个是求斜率最大值,不是求满足斜率大于一定值的最大长度的.也构造不 ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
- uvalive 4851 Restaurant(扫描法)
题意:有一个M*M的网格,坐标[0...M-1,0...M-1] 网格里面有两个y坐标同样的宾馆A和B.以及n个餐厅,宾馆AB里面各有一个餐厅,编号1,2,其它餐厅编号3-n.如今你打算新开一家餐厅. ...
- UVALive 6663 Count the Regions --离散化+DFS染色
题意:给你n(n<=50)个矩形(左上角坐标和右下角坐标),问这些矩形总共将平面分成多少个部分.坐标值可能有1e9. 分析:看到n和坐标的范围,容易想到离散化,当时就没想到离散化以后怎么判断区域 ...
- [UVALive 6663 Count the Regions] (dfs + 离散化)
链接:https://icpcarchive.ecs.baylor.edu/index.php? option=com_onlinejudge&Itemid=8&page=show_p ...
- UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...
- UvaLive 6663 Count the Regions 离散化+DFS
链接:http://vjudge.net/problem/viewProblem.action?id=49408 题意:在平面内给出若干个矩形,求出它们能将整个平面分成多少份. 思路:刚開始一眼看到认 ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
随机推荐
- (十)springmvc之文件的处理
一.同步上传文件 导入common-fileupload这个jar包. 配置 springmvc-servlet.xml <?xml version="1.0" en ...
- vue 数组对象取对象的属性: Cannot read property 'xxxx' of undefined
{{ list[0].name }} list[0]没有定义 能正确打印出想要的结果,但就是报错,外面套个v-for就没错了 很费解 看到文章说是与异步有关,解决办法: <template v- ...
- C# Combox控件绑定自定义数据
DataTable dt = new DataTable(); dt.Columns.Add("name"); dt.Columns.A ...
- Python练习_高阶函数_day11
1,写函数,传入n个数,返回字典{‘max’:最大值,’min’:最小值} 例如:min_max(2,5,7,8,4) 返回:{‘max’:8,’min’:2}(此题用到max(),min()内置函数 ...
- css 布局方式
布局方式 1 布局:设置元素在网页中的排列方式及显示效果 2 分类: 1 标准流布局(文档流,普通流,静态流) 是默认的布局方式 特点:将元素按照书写顺序及元素类型,从上至下,从左至右排列 2 浮动布 ...
- 【leetcode】566. Reshape the Matrix
原题 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ne ...
- window下redis的安装和使用
1.下载及安装redis 下载地址:https://github.com/dmajkic/redis/downloads 找到对应的版本下载安装 打开cmd窗口,用cd命令进入到安装redis的根目录 ...
- 06 Windows编程——设备句柄 和 WM_PAINT消息
windows程序在现实方式上属于图形方式,和文字方式的显示,有显著的不同. 什么是设备句柄,如何获取 使用统一的数据结构表示某一设备,这个结构就是设备句柄. 源码 #include<Windo ...
- webstorm 2018.2.5最新激活方式
亲测时间 2019年6月27日 08:45:52 下载破解文件: https://pan.baidu.com/s/1CMh5AYgewZflMVWL9BO-hA 打开webstorm / bi ...
- 查看python和NumPy版本和安装路径
记录查看Python和NumPy版本以及路径的几条命令 # 查看Python版本及路径 python -V python -c "import sys;print(sys.executabl ...