程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVA10382 Watering Grass

UVA10382 Watering Grass

編輯:C++入門知識

Problem E
Watering Grass
Input:
standard input
Output: standard output
Time Limit: 3 seconds

n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each sprinkler is installed at the horizontal center line of the strip. For each sprinkler we are given its position as the distance from the left end of the center line and its radius of operation.

What is the minimum number of sprinklers to turn on in order to water the entire strip of grass?

\

Input

Input consists of a number of cases. The first line for each case contains integer numbers n, l and w with n <= 10000. The next n lines contain two integers giving the pZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc2l0aW9uIG9mIGEgc3ByaW5rbGVyIGFuZCBpdHMgcmFkaXVzIG9mCiBvcGVyYXRpb24uIChUaGUgcGljdHVyZSBhYm92ZSBpbGx1c3RyYXRlcyB0aGUgZmlyc3QgY2FzZSBmcm9tIHRoZSBzYW1wbGUgaW5wdXQuKTwvcD4KPHA+IDwvcD4KPHA+PHN0cm9uZz5PdXRwdXQ8L3N0cm9uZz48L3A+CjxwPkZvciBlYWNoIHRlc3QgY2FzZSBvdXRwdXQgdGhlIG1pbmltdW0gbnVtYmVyIG9mIHNwcmlua2xlcnMgbmVlZGVkIHRvIHdhdGVyIHRoZSBlbnRpcmUgc3RyaXAgb2YgZ3Jhc3MuIElmIGl0IGlzIGltcG9zc2libGUgdG8gd2F0ZXIgdGhlIGVudGlyZSBzdHJpcCBvdXRwdXQgLTEuPC9wPgo8aDM+U2FtcGxlIGlucHV0PC9oMz4KPHA+OCAyMCAyPC9wPgo8cD41IDM8L3A+CjxwPjQgMTwvcD4KPHA+MSAyPC9wPgo8cD43IDI8L3A+CjxwPjEwIDI8L3A+CjxwPjEzIDM8L3A+CjxwPjE2IDI8L3A+CjxwPjE5IDQ8L3A+CjxwPjMgMTAgMTwvcD4KPHA+MyA1PC9wPgo8cD45IDM8L3A+CjxwPjYgMTwvcD4KPHA+MyAxMCAxPC9wPgo8cD41IDM8L3A+CjxwPjEgMTwvcD4KPHA+OSAxPC9wPgo8cD4gPC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">Sample Output

6

2

-1


(Regionals 2002 Warm-up Contest, Problem setter: Piotr Rudnicku)


題意:有一個草坪,在草坪中有一些噴水裝置,給出這個草坪的長和寬,和噴水裝置的位置和半徑,求最少放置多少個噴水裝置能使得草坪被全部覆蓋?

思路:題目一看,就知道是區間覆蓋問題,用貪心解決,因為是圓形區域覆蓋不好計算,我們把圓形區域轉換到草坪上來,就變成了矩形區域,這樣就比較好計算了。

#include
#include
#include

using namespace std;

class Circle
{
public:
	double left,right;
}circle[10005];


int main()
{
	int num;
	double lenth,width;
	while(cin>>num>>lenth>>width)
		{
			int i,j,k=0;
			double pos,radius;
			for(i=0;i>pos>>radius;
					if(radius*2>=width)
						{
							double l,r;
							l=pos-sqrt(radius*radius-(width/2)*(width/2));
							r=pos+sqrt(radius*radius-(width/2)*(width/2));
							circle[k].left=l;
							circle[k++].right=r;
						}
				}
			double begin=0,end=lenth;
			double maxlen=0;
			int cnt=0;
			while(beginmaxlen)
								{
									maxlen=circle[i].right;
								}
						}
					if(maxlen==begin)
						{
							cnt=-1;
							break;
						}
					cnt++;
					begin=maxlen;
				}
			cout<

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved