UVA 2290 Transmitters
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=291
cross product: for 2 vectors a and b, if a^b > 0, a is in the clockwise direction of b. else if a^b < 0, a is in the anti-clockwise direction of vector b. Otherwise, a^b==0, vector a and b are with the same direction or opposite direction.这道题用cross product计算。每一个点与transmitter的中心形成一个vector,对于每一个vector,循环剩余的vector,所有vector在同一方向的可以看做被覆盖的点。代码如下:
//============================================================================
// Name : test.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
#include <sstream>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <cmath>
#include <set>
#define SCF(a) scanf("%d", &a)
#define IN(a) cin>>a
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define Infinity 999999999
#define PI 3.14159265358979323846
typedef long long Int;
using namespace std; struct point {
int x, y;
}; double dis(point a, point b)
{
return pow(a.x - b.x, ) + pow(a.y - b.y, );
} double length(point a)
{
return sqrt(pow(a.x, ) + pow(a.y, ));
} double dotProduct(point a, point b)
{
return a.x*b.x + a.y*b.y;
} double crossProduct(point a, point b)
{
return a.x*b.y - b.x*a.y;
} double cosAngle(point a, point b)
{
double an = dotProduct(a, b) / (length(a)*length(b));
return an;
} int main()
{
point radar;
double r;
int N;
point points[];
double angle[];
while (scanf("%d %d %lf", &radar.x, &radar.y, &r) != EOF)
{
if (r < )
break;
SCF(N);
int index = ;
point cp;
FOR(i, , N)
{
SCF(cp.x);
SCF(cp.y);
if (dis(radar, cp) <= pow(r, ))
{
points[index].x = cp.x - radar.x;
points[index++].y = cp.y - radar.y;
}
} int maxAns = ;
FOR(i, , index)
{
int cn = ;
FOR(j, , index)
{
if (i != j)
{
double rela = crossProduct(points[i], points[j]);
if (rela >= )
cn++;
}
}
maxAns = max(maxAns, cn);
}
printf("%d\n", maxAns);
}
return ;
}
UVA 2290 Transmitters的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
随机推荐
- 用360清理了一下电脑后发现Eclipse软件无法打开
今天用360安全卫士清理了一下电脑,然后双击Eclipse软件发现不能打开,弹出以下界面: 解决方法如下: 打开计算机-属性-高级系统设置,修改系统变量里变量名为JAVA_HOME.CLASSPATH ...
- 嵌入式linux——汇编、C语言基础(一)
一.汇编语言基础 (断断续续的记录自己的笔记...2018-10-11) 1. mov指令 基本用法: mov r0, #0 mov指令是赋值指令,用法如上,把立即数0放入到寄存器r0中. 2. bl ...
- Docker 多主机方案
利用OpenVSwitch构建多主机Docker网络 [编者的话]当你在一台主机上成功运行Docker容器后,信心满满地打算将其扩展到多台主机时,却发现前面的尝试只相当于写了个Hello World的 ...
- delphi:Exception EInvalidPointer in module Project1.exe
在用delphi XE5编程时遇到如下问题: Exception EInvalidPointer in module Project1.exe at 00007595. Invalid pointer ...
- Redis 4.0.2.3 for Windows (alpha) 下载地址
下载地址如下: https://github.com/tporadowski/redis/releases 如果直接使用redis-server.exe启动报错的话,就使用redis-server.e ...
- Linux系统下常用命令
yum [options] [command] [package ...] options:可选,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装 ...
- [Flutter] 因为不讲这个重点, 全网所有 flutter 实战视频沦为二流课程
二流课程也有其存在的价值,看到不同组件的轮流使用也是不断熟悉的过程,不过太眼花缭乱了. 授人以渔,基础用法是其一,讲清套路是其二,不然坑萌新. 那么 flutter 的套路是什么呢,我认为有下面几点: ...
- 将php脚本加入开机启动
可以看到“/etc/rc.d/init.d”下有很多的文件,每个文件都是可以看到内容的,其实都是一些shell脚本.系统服务的启动就是通过“/etc/rc.d/init.d”中的脚本文件实现的.我们也 ...
- VS2017编译SNMP++步骤记录
1.下载地址:https://www.agentpp.com/download.html 三个都下 2.新建解决方案 TestSnmp 3.下载后解压到解决方案文件夹(注意,解压后的 snmp++的版 ...
- css中有三个显示和隐藏的单词比较常见,display visibility 和 overflow我们需要区分开来
display display 设置或检索对象是否及如何显示 display: none 隐藏对象与它相反的是display:block 除了转换为块级元素之外,同时还有显示元素的意思 特点: 隐藏之 ...