24h購物| | PChome| 登入
2013-08-11 15:13:41| 人氣1,763| 回應0 | 上一篇 | 下一篇

[UVA] 10882 - Koerner's Pub

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

Problem E
Koerner's Pub
Time Limit: 1 second

"Homer no function beer well without."
Homer Simpson

Every Friday night, Alice, Clara and Mary go to Koerner's pub to relax after a long week. At the pub, lots of guys ask them for their phone numbers. In fact, the three ladies are so popular that they have started counting the number of times each one is asked for her phone number during one evening. On day i, Alice, Clara and Mary were asked Ai, Ci and Mi times, respectively. 100 Fridays have passed, and the records were lost, but there are 3 things Alice still remembers.

  1. X of the 100 days, Ai was equal to Ci.
  2. Y of the 100 days, Ci was equal to Mi.
  3. Z of the 100 days, Ai was equal to Mi.
How many time were Ai, Ci and Mi all equal?

Input
The first line of input gives the number of cases, N. N test cases follow. Each one contains the integers X, Y and Z on a line.

Output
For each test case, output one line containing "Case #x:" followed by "Between A and B times.", where A and B are the lowest and highest number of times that Ai, Ci and Mi could have been equal. If the situation is impossible, print "The records are faulty." instead.

Sample Input Sample Output
5
50 50 50
100 100 99
100 50 50
101 50 50
100 100 100
Case #1: Between 25 and 50 times.
Case #2: The records are faulty.
Case #3: Between 50 and 50 times.
Case #4: The records are faulty.
Case #5: Between 100 and 100 times.


Problemsetter: Igor Naverniouk
Alternate solution: Yury Kholondyrev


題目描述:


三個人,在 100 天內,在每一天都有不同個數人向這三個人要電話號碼,
告訴你,他們有兩兩具有 X, Y, Z 天相等,問有多少天三個人都具有相同的數量。

題目解法:


這是一個不等式的計算。

考慮最少天數
假設相同天數 w, 對於 Mary 來說, 只與 Alice 有 z-w 天, 只與 Clara 有 y-w 天,
對於 Clara 來說, 存在 x-w 天是單獨與 Alice, 因此在 Mary 看來是不會有任何一天相同。

則對於 Mary 來說, (x-w)+(y-w)+(z-w)+w <= 100, 便可得到 w。

考慮最多天即 min(x, y, z)

#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    int testcase, cases = 0;
    int x, y, z;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d %d %d", &x, &y, &z);
        int r = min(x, min(y, z));
        int l = (x+y+z-100+1)/2;//ceil
        if(x+y+z <= 100)
            l = 0;
        if(l <= r && l >= 0)
            printf("Case #%d: Between %d and %d times.\n", ++cases, l, r);
        else
            printf("Case #%d: The records are faulty.\n", ++cases);
    }
    return 0;
}

台長: Morris
人氣(1,763) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 11246 - K-Multiple Free set
此分類上一篇:[UVA] 10751 - Chessboard

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