原题链接

题目大意:有一个发射站,覆盖范围是半径一定的一个半圆。在一个1000*1000平方米的地盘里有很多接收站。给定发射站的圆心,求最佳角度时能覆盖接收站的个数。

解法:本质上就是给一个原点和其他若干点,找出一个可以覆盖最多点的半圆。用了两个函数判断,一个是判断两点之间的距离,即该点到原点的距离是否在半径之内,筛选出第一步满足的点。另一个是判断两个点A、B是否在同一个半圆内,其实先确定一条直线AO,然后规定B点在AO的左侧就算在半圆内。每个点都遍历一次,找出最大值即可。

参考代码:

#include<iostream>
#include<cmath> using namespace std;
bool isInclude(int xx, int yy);
bool isCovered(int*, int*);
double cx,cy,r; int main(){ int xx,yy,point[150][2];
int i,j,k,n,m,count,max; while(cin>>cx>>cy>>r&&r>=0){
cin>>n;
m=0;
max=0;
for(i=0;i<n;i++){
cin>>xx>>yy;
if(isInclude(xx,yy)){
point[m][0]=xx;
point[m][1]=yy;
m++;
}
}
for(j=0;j<m;j++){
count=1;
for(k=0;k<m;k++){
if(k==j)continue;
if(isCovered(point[j],point[k]))
count++;
if(count>max)
max=count;
}
}
cout<<max<<endl;
} return 0;
} bool isInclude(int xx,int yy){
double d;
d=(xx-cx)*(xx-cx)+(yy-cy)*(yy-cy); //求两点的欧式距离
d=sqrt(d);
if(d<=r)
return true;
else
return false;
} bool isCovered(int *A, int *B){
int ax,ay,bx,by;
double cc;
ax=A[0];bx=B[0];
ay=A[1];by=B[1];
cc=(ax-cx)*(by-cy)-(ay-cy)*(bx-cx);//判断点是否在直线的同一侧
if(cc>0)
return false;
else
return true;
}

ZOJ 1041 Transmitters的更多相关文章

  1. [ACM_几何] Transmitters (zoj 1041 ,可旋转半圆内的最多点)

    Description In a wireless network with multiple transmitters sending on the same frequencies, it is ...

  2. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  3. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  4. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  7. BZOJ 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3621  Solved: 1605[Submit][Sta ...

  8. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  9. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

随机推荐

  1. DataGridView复选框实现单选功能(二)

    双击DataGridView进入事件 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventA ...

  2. appjs desktop2

    var express = require('express');var path = require('path');var favicon = require('serve-favicon');v ...

  3. MongoDB常用操作一查询find方法db.collection_name.find()

    来:http://blog.csdn.net/wangli61289/article/details/40623097 https://docs.mongodb.org/manual/referenc ...

  4. [开发笔记]-控制Windows Service服务运行

    用代码实现动态控制Service服务运行状态. 效果图: 代码: #region 启动服务 /// <summary> /// 启动服务 /// </summary> /// ...

  5. CCNA 6.5

    no sh (no shutdown : start the interface)   router rspf 1 network x.x.x.x x.x.x.x area 0 int (interf ...

  6. VMWare三种工作模式 :bridge、host-only、nat

    VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作模式.这里 ...

  7. xml文件有误

    Unable to start activity ComponentInfo{com.anzi.jmsht.scripturelibrary/com.anzi.jmsht.scripturelibra ...

  8. js 中 setInterval 的返回值问题

    var i = 0; var timer = setInterval(function() { i++ console.log(i); //alert(1); }, 2000); alert( typ ...

  9. stm32启动文件 startup_stm32f10x_hd.s

    ;* 文件名          : startup_stm32f10x_hd.s;* 库版本           : V3.5.0;* 说明:             此文件为STM32F10x高密度 ...

  10. Stm32_调试出现 Error:Flash Download Failed-"Cortex-M3"

    rror:Flash Download Failed-"Cortex-M3"出现一般有两种情况: 1.SWD模式下,Debug菜单中,Reset菜单选项(Autodetect/HW ...