模拟+贪心 URAL 1804 The Machinegunners in a Playoff

 

题目传送门

题意:A队和B队踢球,已知一场比赛A和B的得分情况,问A最小再得几分就能胜利还有最多能的几分还能给B队一丝翻盘的希望。规则如下:

    1. 总分数相等的情况下,在客场得分高的获胜,如果还相等,那么两者都可能获胜

    2. 总分数高的获胜

分析:首先假设给出home的分数,A的记为x1, B的记为y1。当x1 >= y1时,最小值x2 == 0,因为y2 == 0,否则先补上x2,使得x1 + x2 == y1 + 0,在考虑客场的因素是否还要+1。至于最大值也是先补全(x1 + x3 == y1 + 30) 然后再考虑客场因素是否-1。away的同理。代码写得冗长,我也没时间精简了。

 

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int N = 1e2 + 10;
const int INF = 0x3f3f3f3f;
string s;

int main(void)	{
	int T;	scanf ("%d", &T);
	getchar ();
	while (T--)	{
		int x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0;
		getline (cin, s);
		int len = s.length ();
		int c = 0;
		if (s[26] == 'h')	{
			int k = 44;
			while (k < len && s[k] >= '0' && s[k] <= '9')	x1 = x1 * 10 + s[k++] - '0';
			bool flag = false;
			for (int i=k; i<len; ++i)	{
				if (s[i] < '0' || s[i] > '9')	{
					if (!flag) continue;
					else	break;
				}
				else	{
					flag = true;
					y1 = y1 * 10 + s[i] - '0';
				}
			}
			if (x1 > y1)	{
				x2 = 0;
			}
			else if (x1 == y1)	{
				x2 = 0;
				if (x2 < y1)	x2++;
			}
			else if (x1 < y1)	{
				x2 = y1 - x1;
				if (x2 < y1)	x2++;
			}

			x3 = y1 + 30 - x1;
			if (x3 > y1)	x3--;
			x3 = min (x3, 30);
			cout << x2 << " " << x3 << endl;
		}
		else	{
			int k = 44;
			while (k < len && s[k] >= '0' && s[k] <= '9')	x1 = x1 * 10 + s[k++] - '0';
			bool flag = false;
			for (int i=k; i<len; ++i)	{
				if (s[i] < '0' || s[i] > '9')	{
					if (!flag) continue;
					else	break;
				}
				else	{
					flag = true;
					y1 = y1 * 10 + s[i] - '0';
				}
			}
			if (x1 > y1)	{
				x2 = 0;
			}
			else if (x1 == y1)	{
				x2 = 0;
			}
			else if (x1 < y1)	{
				x2 = y1 - x1;
			}

			x3 = y1 + 30 - x1;
			x3 = min (x3, 30);
			cout << x2 << " " << x3 << endl;
		}
	}

	return 0;
}

  

posted @ 2015-09-06 13:43  Running_Time  阅读(188)  评论(0编辑  收藏  举报