洛谷 P2911 [USACO08OCT]Bovine Bones G C/C++ O(1)解法

  • 面数相同
123456
1234567
2345678
3456789
45678910
567891011
6789101112

两个面的数字和概率最大为数字 :6+1 = 7
即7共出现了6次


  • 面数不同
12345
123456
234567
345678
456789
5678910
67891011
789101112
8910111213

两个面的数字和概率最大为数字 :5+1 = 6 到 8+1=9
即6, 7, 8, 9都出现了5次

参考链接:传送门


#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 1e5+1;
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
int cmp(int x,int y) {
	return x<y;
}
int main() {
#ifdef LOCAL 
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int buf[3];
	for(int i = 0;i<3;i++) {
		cin>>buf[i];
	}
	sort(buf,buf+3,cmp);
	
	int len = buf[2]+1-(buf[0]+1)+1;
	if(buf[1]<=len)cout<<buf[0]+1+buf[1];
	else cout<<buf[2]+1+1+(buf[1]-len)/2;
	
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值