UVA1616-Caravan Robbers(枚举)

Problem UVA1616-Caravan Robbers

Accept: 160  Submit: 1156
Time Limit: 3000 mSec

Problem Description

OnceuponatimetherewasagreedyKing who ordered his chief Architect to build a field for royal cricket inside his park. The Kingwassogreedy, thathewouldnotlisten to his Architect’s proposals to build a fieldrightintheparkcenterwithpleasant patterns of trees specially planted around and beautiful walks inside tree alleys for spectators. Instead, he ordered neither to cut nor to plant even a single tree in his park, but demanded to build the largest possible cricket field for his pleasure. If the Kind finds that the Architect hasdaredtotouchevenasingletreeinhis park or designed a smaller field that it was possible, then the Architect will loose his head. Moreover, he demanded his Architect to introduce at once a plan of the field with its exact location and size. YourtaskistohelppoorArchitecttosavehishead,bywritingaprogramthatwillfindthemaximum possible size of the cricket field and its location inside the park to satisfy King’s requirements. Thetaskissomewhatsimplifiedbythefact,thatKing’sparkhasarectangularshapeandissituated onaflatground. Moreover, park’sbordersareperfectlyalignedwithNorth-SouthandEast-Westlines. At the same time, royal cricket is always played on a square field that is also aligned with North-South andEast-Westlines. ArchitecthasalreadyestablishedaCartesiancoordinatesystemandhasprecisely measured the coordinates of every tree. This coordinate system is, of course, aligned with North-South and East-West lines. Southwestern corner of the park has coordinates (0, 0) and Northeastern corner of the part has coordinates (W,H), where W and H are the park width and height in feet respectively. For this task, you may neglect the diameter of the trees. Trees cannot be inside the cricket field, butmaybesituatedonitsside. Thecricketfieldmayalsotouchpark’sborder, butshallnotlieoutside the park.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The first line of the input file contains three integer numbers N, W, and H, separated by spaces. N (0 ≤ N ≤ 100) is the number of trees in the park. W and H (1 ≤ W,H ≤ 10000) are the park width and height in feet respectively. Next N lines describe coordinates of trees in the park. Each line contains two integer numbers Xi and Yi separated by a space (0 ≤ Xi ≤ W, 0 ≤ Yi ≤ H) that represent coordinates of i-th tree. All trees are located at different coordinates.

 Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. Write to the output file a single line with three integer numbers P, Q, and L separated by spaces, where (P,Q) are coordinates of the cricket field Southwestern corner, and L is a length of its sides. If there are multiple possible field locations with a maximum size, then output any one. Note: This is a sample input and output that corresponds to the park plan that is shown on the picture.
 

 Sample Input

1
7 10 7
3 2
4 2
7 0
7 3
4 5
2 4
1 7
 

Sample Output

4 3 4

题解:本来想用单调栈,一看数据范围,果断枚举,枚举横坐标的两个端点,遍历所有可能的纵坐标,更新答案即可。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int maxn = 100 + 10;
 6 
 7 int n, r, c;
 8 
 9 struct Tree {
10     int x, y;
11     Tree() {}
12     Tree(int _x, int _y) : x(_x), y(_y) {}
13     bool operator < (const Tree &a)const {
14         return y < a.y;
15     }
16 }tree[maxn];
17 
18 int main()
19 {
20     //freopen("input.txt", "r", stdin);
21     //freopen("output.txt", "w", stdout);
22     int iCase;
23     scanf("%d", &iCase);
24     bool flag = false;
25     while (iCase--) {
26         if (flag) printf("
");
27         flag = true;
28         scanf("%d%d%d", &n, &c, &r);
29         for (int i = 0; i < n; i++) {
30             scanf("%d%d", &tree[i].y, &tree[i].x);
31         }
32         tree[n] = Tree(0, 0);
33         tree[n + 1] = Tree(r, 0);
34         n += 2;
35         sort(tree, tree + n);
36 
37         int Max = 0, ansx = 0, ansy = 0;
38         for (int i = 0; i < n; i++) {
39             for (int j = i + 1; j < n; j++) {
40                 int lx = min(tree[i].x, tree[j].x);
41                 int rx = max(tree[i].x, tree[j].x);
42                 int len = rx - lx, now = 0;
43                 
44                 for (int k = 0; k < n; k++) {
45                     if (lx < tree[k].x && tree[k].x < rx) {
46                         int a = tree[k].y - now < len ? tree[k].y - now : len;
47                         
48                         if (a > Max) {
49                             Max = a;
50                             ansx = lx, ansy = now;
51                         }
52                         now = tree[k].y;
53                     }
54                 }
55 
56                 int a = c - now < len ? c - now : len;
57                 if (a > Max) {
58                     Max = a;
59                     ansx = lx, ansy = now;
60                 }
61             }
62         }
63         
64         printf("%d %d %d
", ansy, ansx, Max);
65     }
66     return 0;
67 }
原文地址:https://www.cnblogs.com/npugen/p/9716525.html