24h購物| | PChome| 登入
2013-02-25 19:38:31| 人氣427| 回應0 | 上一篇 | 下一篇

[UVA][多邊形] 11473 - Campus Roads

推薦 0 收藏 0 轉貼0 訂閱站台

 
Problem C
Campus Roads
Time Limit : 2 seconds

 

 

NGU has a beautiful campus. The authority of NGU has decided to take some more steps about beautification of this campus. One of these steps is tree plantation in some roads. To complete this project they will select some roads, and for any road they will also select a number that how many tree will be planted on that road. To make this campus more beautiful they decided in a single road, the gap between any two adjacent tree will be fixed, and this gap will be as large as possible. So If you walk through the road in a constant speed, you will reach a tree after constant intervals.

A road can be described by K points P1, P2, ...... , PK. Pi and Pi+1 are connected by a straight line. So, it is clear that a road consists of some contiguous straight lines.  

In this problem you have to find all the points, where to plant a tree. For the sake of simplicity, we will consider that roads will not have any width.

 

 
  Input    
  The first line of input is an integer N (N<100) that indicates the number of roads under this beautification project. From next line N roads is described one by one. Description of each road starts with a line containing two integers K (2≤K≤100) and T (2≤T≤100).  Here K represents number of points that represents the road, and T represents the number of trees to be planted. This line is followed by K lines having 2 integers x, y(-1000.00<=x<=1000.00 and -1000.00<=y<=1000.00) each, ith line of these K lines is the co-ordinate of  Pi.

 

 
     
  Output  
  You have to give your output for every roads one by one. Output of each road starts with a line "Road #n:" (without quotes), here n is the road number. Next T lines will give the co-ordinates of  trees to be planted. x, y co-ordinate will be separated by a single space and having two decimal points. You have to represent the points sequentially in the order in which order you will find those trees when you walk through the road P1 to PK. Print a blank line after describing each road.  
     
  Sample Input Sample Output    
  1
5 6
10.00 10.00
20.00 20.00
30.00 10.00
10.00 0.00
9.00 9.00
Road #1:
10.00 10.00
18.44 18.44
26.89 13.11
23.26 6.63
12.58 1.29
9.00 9.00

   
  Hint: You have to maximize the distance between two adjacent trees in a road. So it is sure that first and last tree will be on the first and last point, i.e. in P1 and Pk.
Problem Setter: Md. Arifuzzaman Arif
Special Thanks: Shamim Hafiz
Next Generation Contest 5
     

根據走的路線,每隔 ? 公尺,放置一棵樹,特別注意,可能一個線段上一次放置好幾棵樹。

#include <stdio.h>
#include <math.h>
#define eps 1e-8
int main() {
    int t, n, m, cases = 0, i, j;
    double x[105], y[105];
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d", &n, &m);
        for(i = 0; i < n; i++)
            scanf("%lf %lf", x+i, y+i);
        printf("Road #%d:\n", ++cases);
        double path = 0, sum = 0, pre = 0;
        for(i = 1; i < n; i++)
            path += sqrt(pow(x[i]-x[i-1], 2)+pow(y[i]-y[i-1],2));
        path /= m-1;
        printf("%.2lf %.2lf\n", x[0], y[0]);
        for(i = 1; i < n; i++) {
            double len = sqrt(pow(x[i]-x[i-1], 2)+pow(y[i]-y[i-1],2));
            double sx = x[i-1], sy = y[i-1], ex = x[i], ey = y[i];
            pre = sum;
            if(sum+len >= path-eps) {
                double d = path - sum;
                sum = 0;
                sx = sx + d/len*(ex-sx);
                sy = sy + d/len*(ey-sy);
                printf("%.2lf %.2lf\n", sx, sy);
                len -= d;
                d = path;
                while(len >= path-eps) {
                    sx = sx + d/len*(ex-sx);
                    sy = sy + d/len*(ey-sy);
                    printf("%.2lf %.2lf\n", sx, sy);
                    len -= path;
                }
            }
            sum += len;
        }
        puts("");
    }
    return 0;
}

台長: Morris
人氣(427) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Trie] 760 - DNA Sequencing
此分類上一篇:[UVA][dp] 12131 - Obfuscation

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文