日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ1328-Radar Installation

發(fā)布時間:2025/3/20 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ1328-Radar Installation 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

描述:

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.?

  We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.?


Figure A Sample Input of Radar Installations

  The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.?

  The input is terminated by a line containing pair of zeros?

  For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.

代碼:

  每一個海島可以在產(chǎn)生一個圓心的范圍,在該范圍內(nèi)的任意雷達都可以覆蓋到該點。要求雷達的最少的數(shù)目,采用貪心的思路,就是使選擇的圓心能夠盡量的屬于更多的圓心的區(qū)間。如果雷達范圍無法到達某個點,則無解。

  邊輸入邊處理的時候,不能break。就因為這個RE了無數(shù)次(╯‵□′)╯︵┴─┴

#include <cmath> #include <cstdlib> #include <iostream> using namespace std; typedef struct{double left;double right; }node; node a[1005]; int cmp(const void *a, const void *b){return (*(node*)a).left >= (*(node*)b).left ? 1 : -1; } int main(){int tc=1,n,d,flag,count,x,y;double delta,t;while( scanf("%d%d",&n,&d)!=EOF ){if( n==0 && d==0 ) break;flag=1;if( d<=0 ) flag=0;for( int i=0;i<n;i++ ){scanf("%d%d",&x,&y);if( y<=d ){//島嶼在雷達范圍delta=sqrt((double)(d*d-y*y));a[i].left=x-delta;//得到區(qū)間a[i].right=x+delta;}else{flag=0;//這里不能寫break,因為輸入還未結束 }}if( flag==0 )//無解printf("Case %d: -1\n",tc);else{qsort(a,n,sizeof(node),cmp); t=a[0].right;count=1;for( int i=1;i<n;i++ ){if( a[i].left>t ){//當前區(qū)間左界大于相交區(qū)間的最右count++;t=a[i].right;//更新相交右界 }else{if( a[i].right<t )//取相交的區(qū)間t=a[i].right;//更新相交區(qū)間右界 }}printf("Case %d: %d\n",tc,count);}tc++;}system("pause");return 0; }

  

轉載于:https://www.cnblogs.com/lucio_yz/p/4771828.html

總結

以上是生活随笔為你收集整理的POJ1328-Radar Installation的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 人妻在线一区 | 久久国产精品一区二区三区 | 日韩图色 | 欧美va在线观看 | 精品一区二区三区蜜桃 | 亚洲一区在线电影 | 亚洲欧洲av在线 | 日韩在线免费播放 | 蜜桃色av| 午夜免费激情视频 | 超碰最新上传 | 成人免费在线视频网站 | 污视频网站免费看 | 欧美高清一区二区 | wwwa级片| 欧美性大交 | 国产91视频在线 | 欧美资源在线观看 | 91精品久久久久久久 | 亚洲激情图片区 | 91福利片| 久久久久人妻一区精品色欧美 | 国产影视一区二区 | 黄色一级片 | 成人不卡| 亚洲a图| 97少妇| 91在线超碰 | 乱图区 | 一区二区国产电影 | 日韩中文字幕第一页 | 综合久久久久综合 | 98精品视频 | 天天舔日日操 | 人妖ts福利视频一二三区 | 日本成片网| 欧美区在线 | 欧美超碰在线观看 | xxxx亚洲| 日韩欧美高清一区 | 美女高潮黄又色高清视频免费 | 成人日韩在线观看 | 在线观看免费黄视频 | 久操av在线| 一本色道久久综合无码人妻 | 久久精品久久精品 | 日韩美女视频在线观看 | 日本丰满大乳奶做爰 | 在线观看色网站 | 夜夜爽av| 日本精品视频一区 | 日本视频一区二区三区 | 97干干 | 2020av视频| 久久精品九九 | 日韩在线激情视频 | 欧美阿v | 中国黄色在线视频 | 黄色91免费| 亚洲色图在线观看视频 | 日本一区二区三区免费观看 | 爱情岛亚洲品质自拍极速福利网站 | 另类欧美尿交 | 日韩欧美黄色片 | 国产欧美一区二区三区白浆喷水 | 九九热这里只有 | 国产亚洲制服欧洲高清一区 | 久久一区二区视频 | 欧美在线中文 | 国产精品19乱码一区二区三区 | 午夜伦理在线观看 | 久久精品国产精品 | 美女扒开屁股让男人捅 | 成人中文字幕+乱码+中文字幕 | a天堂资源 | 男女草逼| 国产高清在线精品 | 日韩大片在线免费观看 | 国产三极片 | 射精一区二区 | av大片免费观看 | 午夜精品视频一区二区三区在线看 | 好吊视频在线观看 | 一级女性全黄久久生活片免费 | 欧美成人看片黄a免费看 | 瑟瑟网站免费 | 在线天堂在线 | 国语对白永久免费 | 天天久| 亚洲国产婷婷香蕉久久久久久99 | 国产又粗又硬 | 18女人毛片| 91超碰在线免费观看 | 神马久久精品 | 亚洲一区免费观看 | 午夜视频观看 | 精品不卡视频 | 在线免费观看av网 | 日本伦理一区二区三区 |