hdu Rich Game 6245

Rich Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 72    Accepted Submission(s): 34


Problem Description
One day, God Sheep would like to play badminton but he can’t find an opponent. So he request Mr. Panda to play with him. He said: “Each time I win one point, I’ll pay you X dollars. For each time I lose one point, you should give me Y dollars back.”
God Sheep is going to play K sets of badminton games. For each set, anyone who wins at least 11 points and leads by at least 2 points will win this set. In other words, normally anyone who wins 11 points first will win the set. In case of deuce (E.g. 10 points to 10 points), it’s necessary to lead by 2 points to win the set.
Mr. Panda is really good at badminton so he could make each point win or lose at his will. But he has no money at the beginning. He need to earn money by losing points and using the money to win points.
Mr. Panda cannot owe God Sheep money as god never borrowed money. What’s the maximal number of sets can Mr. Panda win if he plays cleverly?
 

 

Input
The first line of the input gives the number of test cases, T . T test cases follow.
Each test case contains 3 numbers in one line, X , Y , K , the number of dollars earned by losing a point, the number of dollars paid by winning a point, the number of sets God Sheep is going to play.
1T105.
1X,Y,K1000.
 

 

Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximal number of sets Mr. Panda could win.
 

 

Sample Input
2 10 10 1 10 10 2
 

 

Sample Output
Case #1: 0 Case #2: 1
Hint
In the first test case, Mr. Panda don’t have enough money to win the only set, so he must lose the only set. In the second test case, Mr. Panda can lose the first set by 0:11 and he can earn 110 dollars. Then winning the second set by 11:0 and spend 110 dollars.
 
 
题意:两人玩游戏,输赢规则和乒乓球类似,不同的是赢一局要付钱给对方,输一局对方会给你钱,现在你初始的资金为0,最多能赢几局。
思路:如果赚的钱大于赔的钱,那么每一局都能赢。
否则输的时候就是0:11;赢得时候就是11:9
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring> 
#include<string>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
typedef vector<double> vec;
typedef vector<vec> mat;
const int N_MAX = 5000;
int in,out,num;
int T;

int main() {
    scanf("%d", &T);
    int k = 0;
    while (T--) {
        k++;
        scanf("%d%d%d",&in,&out,&num);
        if (out < in) {
            printf("Case #%d: %d\n",k,num);
        }
        else{
            int res = 0,remain=0;
            while (num--) {
                int pay = (out * 11 - in * 9);
                if (remain <pay ) {//付不起钱,这句要输
                    remain += in * 11;
                }
                else {
                    remain-= pay;
                    res++;
                }
            }
            printf("Case #%d: %d\n", k, res);
        }
    }
    return 0;
}

 

 

posted on 2017-12-12 17:24  ZefengYao  阅读(296)  评论(0编辑  收藏  举报

导航