UVa 428 - Swamp County Roofs

contents

  1. 1. Problem
  2. 2. Input
  3. 3. Output
  4. 4. Sample Input
  5. 5. Sample Output
  6. 6. Solution

Problem

The Swamp County Environmental Office is concerned about the number of structures in the county. They have a theory that all the rain water landing on roofs of buildings, parking lots, roads, and highways is going down the sewage system instead of draining to the ecologically sensitive and historically important swamp land the county is famous for.

Your team has been hired to do the analysis of rain water captured by building roofs. The Planning Commission, which processes all building permits, and hence knows the plans of every structure in the county, will provide the data. Their database contains a set of measurements for the roofs of every building on every lot in the county.

The Engineering staff of the Planning Commission has determined that all the roofs in the county can be represented by one or more quadrilaterals. Each quadrilateral has the following characteristics:

length of baseline, in feet;
length of ridgeline, in feet;
distance between baseline and ridgeline, in feet;
and inclination of the roof segment, in degrees. 

The baseline is always parallel to the ridgeline. A roof segment is always flat, but may be inclined. The inclination of the segment occurs along the baseline or ridgeline axis. A roof segment that is inclined 90 degrees is a wall that is assumed to have negligible thickness, and hence gathers no rain–such a segment will not appear in the data. Assume that the buildings are on level land, and that no roof segment overlaps any other. A roof segment may have either a baseline or ridgeline length of zero (such a segment is actually a triangle). A lot may contain one or more buildings, but your program need only compute the area covered by roofs on a lot-by-lot basis.

Input

Each lot is represented by a series of numbers separated from each other by white space and/or new-lines. The lot size, in square feet, is followed by a list of roof segments. Each roof segment will consist of the length of the baseline, the length of the ridgeline, the distance between the baseline and the ridgeline, and the inclination. Each lot description including the last will end with a blank line.

Output

For each lot compute and print the following statistics: the total roof surface area of buildings in square feet, the total floor space covered by roofs in square feet, and the percentage of rain intercepted by roofs. Print these values in labeled columns, one lot per line, with two digits after the decimal point. Print percent signs after the percentage of rain figures.

At the end of the run compute and print the following statistics: the total roof surface area of all roofs in the county, the total floor space covered by roofs in the county, the overall percentage of rain intercepted by roofs, the average roof surface area on a lot, and the average floor space covered by roofs on a lot. Skip a line after the per-lot listing and print these values on separate lines with appropriate labels.

Print each value with two digits after the decimal point. Print a percent sign after the overall percentage of rain value. Use a report format similar to that of the sample output below.

One of the reasons Swamp County has remained so is the relative lack of wind in the county–you may therefore assume that all rain falls vertically.

Sample Input

1
2
3
4
100 10 10 10 60
10 10 10 60
200 5 10.5 5 30 10 10 7.5 45

Sample Output

1
2
3
4
5
6
7
8
9
10
Roof Area Floor Area % Covered
--------- ---------- ---------
200.00 100.00 100.00%
113.75 86.59 43.30%
Total surface area of roofs 313.75
Total area covered by roofs 186.59
Percentage of total area covered by roofs 62.20%
Average roof surface area per lot 156.88
Average floor space covered per lot 93.30

Solution

題目描述:

屋頂為一個三維空間的平面,假想成梯形也可以,頃角就是單純地將梯形與平面 x-y 夾角 theta。

分別算出梯形面積和陰影面積。

題目解法:

最坑的就是輸入,其實看了很久都沒有明白到底是怎麼區隔每一組。
查閱了討論區給的測資才湊出 AC 代碼。

想辦法讀到每一組測資是 4n + 1 個數字,否則繼續將空白行讀入。

brianfry713’s Input:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
100 10 10 10 60
10 10 10 60
200 5 10.5 5 30 10 10 7.5 45
100
10 10 10
60 10
10 10 60
200 5 10.5 5 30 10 10 7.5 45
100 0 10 7.5 45 10
0 7.5 -135
300

brianfry713’s Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Roof Area Floor Area % Covered
--------- ---------- ---------
200.00 100.00 100.00%
113.75 86.59 43.30%
0.00 0.00 0.00%
600.00 590.88 5908.85%
7701.25 7133.96 71339.57%
0.00 0.00 0.00%
Total surface area of roofs 8615.00
Total area covered by roofs 7911.43
Percentage of total area covered by roofs 1098.81%
Average roof surface area per lot 1435.83
Average floor space covered per lot 1318.57

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <sstream>
#include <iostream>
#include <math.h>
using namespace std;
const double pi = acos(-1);
double A, B, C, N;
char* getLot() {
char line[1024], *v;
string ret = "", token;
int tokenCnt = 0;
while(tokenCnt%4 != 1) {
while((v = gets(line)) && line[0] != '\0') {
ret += " ", ret += line;
stringstream ss(line);
while(ss >> token)
tokenCnt++;
}
if(!v)
return v;
}
stringstream sin(ret);
double lotsize, baseline, ridgeline, dist, theta;
double a = 0, b = 0;
sin >> lotsize;
while(sin >> baseline >> ridgeline >> dist >> theta) {
a += (baseline + ridgeline) * dist/2.0;
b += (baseline + ridgeline) * dist/2.0 * cos(theta / 180.0 * pi);
}
printf("%9.2lf %10.2lf %8.2lf%%\n", a, b, b * 100 /lotsize);
A += a, B += b, C += lotsize, N++;
return v;
}
int main() {
// freopen("in.txt", "r+t", stdin);
// freopen("out.txt", "w+t", stdout);
puts("Roof Area Floor Area % Covered");
puts("--------- ---------- ---------");
char line[1024];
while(true) {
if(getLot()) {
} else {
break;
}
}
puts("");
printf("Total surface area of roofs %10.2lf\n", A);
printf("Total area covered by roofs %10.2lf\n", B);
printf("Percentage of total area covered by roofs %6.2lf%%\n", B*100/C);
printf("Average roof surface area per lot %10.2lf\n", A/N);
printf("Average floor space covered per lot %10.2lf\n", B/N);
return 0;
}