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; }
时间: 2024-10-21 19:05:00