1. 程式人生 > >HDU 5531 Rebuild(三分)——2015ACM/ICPC亞洲區長春站

HDU 5531 Rebuild(三分)——2015ACM/ICPC亞洲區長春站

傳送門

Rebuild

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2483    Accepted Submission(s): 548


Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild it.

The ruins form a closed path on an x-y plane, which has n
endpoints. The endpoints locate on (x1,y1), (x2,y2), ,(xn,yn) respectively. Endpoint i and endpoint i1 are adjacent for 1<in, also endpoint 1 and endpoint n are adjacent. Distances between any two adjacent endpoints are positive integers.

To rebuild, they need to build one cylindrical pillar at each endpoint, the radius of the pillar of endpoint i
is ri. All the pillars perpendicular to the x-y plane, and the corresponding endpoint is on the centerline of it. We call two pillars are adjacent if and only if two corresponding endpoints are adjacent. For any two adjacent pillars, one must be tangent externally to another, otherwise it will violate the aesthetics of Ancient ACM Civilization. If two pillars are not adjacent, then there are no constraints, even if they overlap each other.

Note that r
i
must not be less than 0 since we cannot build a pillar with negative radius and pillars with zero radius are acceptable since those kind of pillars still exist in their neighbors.

You are given the coordinates of n endpoints. Your task is to find r1,r2,,rn which makes sum of base area of all pillars as minimum as possible.



For example, if the endpoints are at (0,0), (11,0), (27,12), (5,12), we can choose (r1, r2, r3, r4)=(3.75, 7.25, 12.75, 9.25). The sum of base area equals to 3.752π+7.252π+12.752π+9.252π=988.816. Note that we count the area of the overlapping parts multiple times.

If there are several possible to produce the minimum sum of base area, you may output any of them.
Input The first line contains an integer t indicating the total number of test cases. The following lines describe a test case.

The first line of each case contains one positive integer n, the size of the closed path. Next n lines, each line consists of two integers (xi,yi) indicate the coordinate of the i-th endpoint.

1t100
3n104
|xi|,|yi|104
Distances between any two adjacent endpoints are positive integers.
Output If such answer doesn’t exist, then print on a single line "IMPOSSIBLE" (without the quotes). Otherwise, in the first line print the minimum sum of base area, and then print n lines, the i-th of them should contain a number ri, rounded to 2 digits after the decimal point.

If there are several possible ways to produce the minimum sum of base area, you may output any of them.
Sample Input
3 
4
0 0
11 0
27 12
5 12
5
0 0
7 0
7 3
3 6
0 6
5
0 0
1 0
6 12
3 16
0 12

Sample Output
988.82 
3.75
7.25
12.75
9.25
157.08
6.00
1.00
2.00
3.00
0.00
IMPOSSIBLE

題目大意:

n 個點,其中這 n 個點能夠組成一個凸 n 邊形,而且是按照順序的,這樣就不用排序了,如果不給定順序的話,應該按照極角進行排序,現在以每個點為圓心,保證兩個相鄰點為圓心的圓是相切的,現在求的是所有的圓的面積和,並且將每個圓的半徑輸出。

解題思路:

因為保證相鄰圓是相切的,所以我們設第一個圓的半徑為 r1 ,那麼有如下式子成立:
r1+r2=d1
r2+r3=d2
...
rn+r1=dn

然後我們來解這個方程,解的過程中就會發現有一個小規律,跟 n 的奇偶有關係,即:當 n 為奇數的時候,就會有唯一解能夠解出 r1r1=d1d2+d3+...+dn2
如果是偶數的話,我們發現解不出這個方程,那麼怎麼做的,因為求的是面積,所以最終的結果一定是關於

相關推薦

HDU 5531 Rebuild——2015ACM/ICPC亞洲區長春站

傳送門 RebuildTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2483    Accep

hdu 5531 Rebuild

題目連結: 題目大意: 給出n個點,這n個點可以連成一個凸多邊形。現在以多邊形的端點作為圓心,分別做n個圓,要求在同一條線上的端點的圓是相切的。現在要求滿足條件以後,計算最小的圓面積總和。如果不能保證條件成立,則輸出impossible。 思路: 如果我們知道了第一個點上

BZOJ3203 SDOI2013保護出題人

for 保護 維護 pan stdout line main sdoi2013 style   給a做一個前綴和,那麽現在每次所查詢的就是(sn-sk)/(bn+nd-(k+1)d)的最大值。這個式子可以看成是(bn+nd,sn)和((k+1)d,sk)所成直線的斜率。  

ACM_求第k大數

求第k大 Time Limit: 6000/3000ms (Java/Others) Problem Description: 給定兩個陣列A和B,大小為N,M,每次從兩個陣列各取一個數相乘放入陣列C,最終得到一個N*M的陣列C。求C中第K大的數。 Input: 輸入包含

TOJ3777 Function Problem

//三分 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath&

#LOJ10013 曲線

題目連結 題目描述 明明做作業的時候遇到了 n 個二次函式 Si(x)=ax^2 + bx + c,他突發奇想設計了一個新的函式 F(x)=max⁡{Si(x)},i=1…n。 明明現在想求這個函式在 [0,1000] 的最小值,要求精確到小數點後四位,四捨五入。

poj3301 Texas Trip

這個三分法對我來說是個比較陌生的東西,就在這裡總結一下 二分法適用於單調函式,但是對於單峰函式的解決,就只能用 三分法求解極值了。 對於三分法的話,給一個大神部落格的連結: http://chenjianneng3.blog.163.com/blog/static/1283

poj 3737 UmBasketella

In recent days, people always design new things with multifunction. For instance, you can not only use cell phone to call your friends, but you can also u

HPUOJ 題目1079 假幣問題

1079: 假幣問題 時間限制: 1 Sec  記憶體限制: 128 MB提交: 7  解決: 1 [提交][狀態][討論版] 題目描述 居然有假幣!!!  事情是這樣的,現在豬肉漲了,但是農民的

@2015ACM/ICPC亞洲區長春站-重現賽感謝東北師大 @HDU5534 (Dp,完全揹包)

題目描述 In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly

HDU 5532 Almost Sorted Array(最長非遞減子序列 模板題)——2015ACM/ICPC亞洲區長春站

Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description We are

hdu 5527】 [2015ACM/ICPC亞洲區長春站] Too Rich 貪心

Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 673 Accept

[hdu 5521][2015ACM/ICPC亞洲區長春站] House Building

House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 624

5120 Intersection簡單幾何——2014ACM/ICPC亞洲區北京站

傳送門 Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famou

[hdu 5534]2015ACM/ICPC亞洲區長春站 Partial Tree  完全揹包

Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 674 Ac

【hdu5538】【2015ACM/ICPC亞洲區長春站 】House Building 題意&題解&程式碼

題目連結: http://acm.hdu.edu.cn/showproblem.php?pid=5538 題意: 給你積木圖的俯檢視,輸入資料表示(i,j)位置放了一個高度為h[i][j]的積木,

【套題】2015ACM/ICPC亞洲區長春站 HDU5532 5533 5534 5536 5538

水幾個題,熟悉一下鍵盤。。。 HDU5532AlmostSortedArray 題意:ASA定義為,僅去掉一個(OneandOnlyOne)元素後陣列是非降序或者非升序。 題解:很明顯,判斷一個序列是否有序可以通過判斷其LongestNonDecreasing

【hdu5534】【2015ACM/ICPC亞洲區長春站】Partial Tree 題意&題解&程式碼

題目連結: http://acm.hdu.edu.cn/showproblem.php?pid=5534 題意: 構造一棵有n個節點的數,f[i]表示度數(入度+出度)為i的節點的點權,給出所有的

HDU 3400 Line belt

while freopen ios logs 三分 分享 -1 txt pri http://acm.split.hdu.edu.cn/showproblem.php?pid=3400 題意: 有兩條帶子ab和cd,在ab上的速度為p,在cd上的速度為q,在其它地方的速

HDU-2438-Turn the corner+思維

Problem DescriptionMr. West bought a new car! So he is travelling around the city. One day he comes to a vertical corner. The street he is currently in ha