zoukankan      html  css  js  c++  java
  • 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
    ",(ll)(sum-6)*6+15);
                continue;
            }
    
            if(!ball[0] && !ball[1])
            {
                printf("%I64d
    ",ball[2]==0||ball[2]==1 ? 0LL :2*ball[2]-3);
                continue;
            }
            if(!ball[0])
            {
                ll ans=0LL;
                if(ball[1]==1){printf("%I64d
    ",(ans=ball[2]==1?1:(ll)(3*ball[2])-3));continue;}
                if(ball[1]>=2){printf("%I64d
    ",(ans=4*(sum-4)+6));continue;}
            }
            if(ball[0] == 1)
            {
                if(ball[1]==1)//printf("%I64d
    ", ball[2]==1 ? 3LL : 3*ball[2]);
                {
                    if(ball[2] == 1)puts("3");
                    if(ball[2] >=2) printf("%I64d
    ",6+4*(ball[2]-2));
                }
                if(ball[1]>1)printf("%I64d
    ", (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;  
    }  


  • 相关阅读:
    hibernate 表配置文件如何设置表字段的默认值
    dtree的使用和扩展
    JS获取项目根目录
    前端 本地缓存图片
    数组去重 和 数组排序方法总结
    js数组去重的方法(转)
    vue 校验插件 veeValidate使用
    将本地已有项目上传到github
    vue 项目搭建笔记1
    css计数器 及 鼠标经过从中间扩散一个矩形(正方形长方形均可)
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7168821.html
Copyright © 2011-2022 走看看