URAL 1534 Football in Gondor

#include <stdio.h>

long long  scoredBalls, missedBalls;
long long  numOfMatches;
long long   max, min;

int main(){

	scanf("%lld%lld%lld", &scoredBalls, &missedBalls, &numOfMatches);

	long long leftScoredBalls, leftMissedBalls;

	if (scoredBalls >= numOfMatches){
		//进球数足够多,一共numOfMatches场比赛中有numOfMatches - 1场比赛都是1比0赢了,剩下的唯一的比赛不是赢了就是平了
		max = 3 * (numOfMatches - 1);
		leftScoredBalls = scoredBalls - numOfMatches + 1;
		if (leftScoredBalls > missedBalls){
			//剩下的一场比赛也赢了
			max += 3;
		} else if (leftScoredBalls == missedBalls){
			//剩下的一场比赛平了
			max += 1;
		}
	} else {
		//进球数不够多,一共numOfMatches场比赛中有scoredBalls场比赛赢了,剩下的比赛不是输了就是平了
		max = 3 * scoredBalls;
		if (missedBalls > 0){
			//剩下的比赛中有一场输了其他平了
		max += 1 * (numOfMatches - scoredBalls - 1);
		} else {
			//剩下的比赛中全平了
			max += 1 * (numOfMatches - scoredBalls);
		}
	}
	
	//类比求最大数的情况
	if (missedBalls >= numOfMatches){
		leftMissedBalls = missedBalls - numOfMatches + 1;
		if (leftMissedBalls < scoredBalls){
			min += 3;
		} else if (leftMissedBalls == scoredBalls){
			min += 1;
		}
	} else {
		if (scoredBalls > 0){
			min += 3;
			min += 1 * (numOfMatches - missedBalls - 1);
		} else {
			min += 1 * (numOfMatches - missedBalls);			}
		}
	
	//坑,进球和失球都在一场比赛,其他比赛都是平局
     long long tempMin = 1 * (numOfMatches - 1);
	if (scoredBalls > missedBalls){
		tempMin += 3;
	} else if (scoredBalls == missedBalls){
		tempMin += 1;
	}
	//例如输入是2 2 2的情况,这样算出来的tempMin会比min更小
	if (tempMin < min){
		min = tempMin;
	}

	printf("%lld %lld\n", max, min);

	return 0;
}



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值