hdu 4811 数学 不难
http://acm.hdu.edu.cn/showproblem.php?
pid=4811
由于看到ball[0]>=2 && ball[1]>=2 && ball[2]>=2 ans=(sum-6)*6+15 sum是三种颜色的球个数的和,然后就想到分类讨论,由于情况是可枚举的。
发现整数假设不加LL直接用%I64d打印会出问题
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std; #define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const double pi = acos(-1.0);
const int INF = 100000000; ll ball[3]; int main()
{
while(~scanf("%I64d%I64d%I64d",&ball[0],&ball[1],&ball[2]))
{
sort(ball, ball+3);
ll sum=ball[0]+ball[1]+ball[2];
if(ball[0]>=2 && ball[1]>=2 && ball[2]>=2)
{ printf("%I64d\n",(ll)(sum-6)*6+15);
continue;
} if(!ball[0] && !ball[1])
{
printf("%I64d\n",ball[2]==0||ball[2]==1 ? 0LL :2*ball[2]-3);
continue;
}
if(!ball[0])
{
ll ans=0LL;
if(ball[1]==1){printf("%I64d\n",(ans=ball[2]==1?1:(ll)(3*ball[2])-3));continue;}
if(ball[1]>=2){printf("%I64d\n",(ans=4*(sum-4)+6));continue;}
}
if(ball[0] == 1)
{
if(ball[1]==1)//printf("%I64d\n", ball[2]==1 ? 3LL : 3*ball[2]);
{
if(ball[2] == 1)puts("3");
if(ball[2] >=2) printf("%I64d\n",6+4*(ball[2]-2));
}
if(ball[1]>1)printf("%I64d\n", (sum-5)*5+10);
}
}
return 0;
}
AC了之后看到别人的代码真是短啊......
http://blog.csdn.net/accelerator_/article/details/25918093
推理一下,发现能够先求出后面放小球能够加分的最大值,然后前面的和为0 + 1 + 2 + ...+ max,max最大为6,由于每一个球最多算左右两边
代码:
#include <iostream>
#include <algorithm>
using namespace std;
long long a, b, c; long long tra(long long num) {
return num > 2 ? 2 : num;
} int main() {
while (cin >> a >> b >> c) {
long long sum = tra(a) + tra(b) + tra(c);
long long hav = max(0ll, a + b + c - sum);
cout << (hav * sum + (sum - 1) * sum / 2) << endl;
}
return 0;
}
hdu 4811 数学 不难的更多相关文章
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
- *HDU 2451 数学
Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂
从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...
- Ball HDU - 4811
Jenny likes balls. He has some balls and he wants to arrange them in a row on the table. Each of tho ...
- hdu 4506(数学,循环节+快速幂)
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4432 数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了.在坚持几天然后ACM退役 ...
- HDU 4811 Ball -2013 ICPC南京区域现场赛
题目链接 题意:三种颜色的球,现给定三种球的数目,每次取其中一个放到桌子上,排成一条线,每次放的位置任意,问得到的最大得分. 把一个球放在末尾得到的分数是它以前球的颜色种数 把一个球放在中间得到的分数 ...
- hdu 5288 数学 ****
给一个序列 定义函数f(l ,r) 为区间[l ,r] 中 的数ai不是在这个区间其他任意数aj的倍数 求所有f(l,r)之和 通过预处理,记录 a[i] 的左右边界(所谓的左右边界时 在从 a[i] ...
随机推荐
- Es5正则
##JSON(ES5) 前端后台都能识别的数据.(一种数据储存格式) XNL在JSON出来前 JSON不支持 undefinde和函数. 示列:let = '[{"useername&qu ...
- 【重构】C# VS 配置引用程序集的路径(分离exe和dll从指定路径调用)
原文:[重构]C# VS 配置引用程序集的路径(分离exe和dll从指定路径调用) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/CocoWu892 ...
- 【习题 8-2 UVA-1610】Party Games
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串排序后 显然是n/2-1和n/2这两个字符串进行比较. 设为a,b 找到第一个不相同的位置. 即0..i-1是相同的前缀,然后 ...
- 【CS Round #39 (Div. 2 only) C】Reconstruct Sum
[Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...
- POJ 2828 线段树单点更新 离线搞
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- 安卓使用WebView下载文件,安卓实现软件升级功能
由于调用系统默认浏览器下载更新,造成用户体验非常不好,所以决定在webview中直接下载系统更新.然后直接安装. 由于要下载,所以必须用webview,联网权限这里不说了,直接写在manifafest ...
- VPS 上线监控监控脚本
文件地址 https://github.com/yourshell/yisuo-script/blob/master/vpstz/vpsmon.zip https://download.csdn.ne ...
- 中间件 —— 消息中间件(MOM)
维基百科对消息中间件的定义为:Message-oriented middleware (MOM) is software or hardware infrastructure supporting s ...
- String类型转Long类型需要注意的问题
转自:https://blog.csdn.net/m819177045/article/details/52669785/
- WdatePicker日期控件的使用
将压缩包中的文件连带文件夹添加到项目中去,注意要完整的添加到项目中去,不要更改了其目录结构 然后在aspx页面中直接使用即可: 首先引入: <script src="/Controls ...