24h購物| | PChome| 登入
2013-07-07 19:31:10| 人氣732| 回應0 | 上一篇 | 下一篇

[UVA] 10865 - Brownie Points

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

Problem A: Brownie Points I

Stan and Ollie play the game of Odd Brownie Points. Some browniepoints are located in the plane, at integer coordinates. Stan playsfirst and places a vertical line in the plane. The line must gothrough a brownie point and may cross many (with the samex-coordinate). Then Ollie places a horizontal line that must crossa brownie point already crossed by the vertical line.

Those lines divide the plane into four quadrants. The quadrantcontaining points with arbitrarily large positive coordinates is thetop-right quadrant.

The players score according to the number of brownie points in thequadrants. If a brownie point is crossed by a line, it doesn'tcount. Stan gets a point for each (uncrossed) brownie point in thetop-right and bottom-left quadrants. Ollie gets a point for each(uncrossed) brownie point in the top-left and bottom-right quadrants.

Your task is to compute the scores of Stan and Ollie given the pointthrough which they draw their lines.

Input contains a number of test cases. The data of each test caseappear on a sequence of input lines. The first line of each test casecontains a positive odd integer1 < n < 200000 which is the numberof brownie points. Each of the following n lines containstwo integers, the horizontal (x) and vertical (y)coordinates of a brownie point. No two brownie points occupy the sameplace. The input ends with a line containing 0 (instead of then of a test).

For each test case of input, print a line with two numbers separatedby a single space. The first number is Stan's score, the second is the score of Ollie when their lines cross the point whose coordinatesare given at the center of the input sequence of points for this case.

Sample input

113 23 33 43 62 -21 -30 0-3 -3-3 -2-3 -43 -70

Output for sample input

6 3

P. Rudnicki

題目解法:

這題乍看起來有點近似於博弈問題,一個人先決定垂直線,接著換另一個人決定水平線。
接著畫分成四個象限,一三象限的點個數給第一個人,其餘給第二個人,點數即分數。

但是那是事實上不用,題目已經給定好輸入序列中的中間點做為畫分對象。


//博弈的話,要正常的窮舉,即是窮舉所有點的分差最低的那個。


#include <stdio.h>
#include <algorithm>
using namespace std;
struct Pt {
    int x, y;
};
Pt D[200000];
int main() {
    int n, i;
    while(scanf("%d", &n) == 1 && n) {
        for(i = 0; i < n; i++)
            scanf("%d %d", &D[i].x, &D[i].y);
        int mx, my;
        int stan = 0, olli = 0;
        mx = D[n/2].x, my = D[n/2].y;
        for(i = 0; i < n; i++) {
            if(D[i].x > mx) {
                if(D[i].y > my)
                    stan++;
                if(D[i].y < my)
                    olli++;
            }
            if(D[i].x < mx) {
                if(D[i].y > my)
                    olli++;
                if(D[i].y < my)
                    stan++;
            }
        }
        printf("%d %d\n", stan, olli);
    }
    return 0;
}

台長: Morris
人氣(732) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][遞迴] 10821 - Constructing BST
此分類上一篇:[UVA][greedy] 10716 - Evil Straw Warts Live

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