zoukankan      html  css  js  c++  java
  • HDU5003:Osu!(签到题)HDU5038:(签到题,题意很坑)

    HDU 5003

    水题,直接上代码(因为题意读错了,WA了一遍)。

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    typedef long long  ll;
    #define inf 0x3f3f3f3f
    #define mod 7
    #include <math.h>
    #include <queue>
    using namespace std;
    int n,a[60];
    int cmp(const void *aa,const void *bb)
    {
        return *(int *)bb-*(int *)aa;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        double sum;
        while(T--)
        {
            scanf("%d",&n);
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
            qsort(a,n,sizeof(a[0]),cmp);
            sum=0;
            for(int i=0;i<n;i++)
            {
                sum+=pow(0.95,i)*a[i];
            }
            printf("%.10lf
    ",sum);
        }
        return 0;
    }

    HDU 5038

    这题的题意真是无比坑啊,还有为么G++超时,C++就过了,尼玛这个大水题浪费了我好几个小时,我百度了一下说只有HDU上面C++快于G++,一般情况下(没算法的情况居多)如果用G++交

    TLE了,请在用C++交一遍。

    再说一下坑人的题意。

    有n个蘑菇,重量为w[i],根据公式为这n个蘑菇分等级(给出一个分数),其中出现频率最多的那个分数成为mode,要求输出这个mode, 注意mode 可能不唯一,按升序输出符合是mode的分数。如果打出的分数每个都可以成为mode,那么则输出 Bad Mushroom.

    可能上边说的不是很明白,为每个蘑菇打出分数后,有三种情况,举例子说明,假设有6个蘑菇:

    1.  打出的分数为   2  2  2   1  1  6

    其中2 出现的次数最多,mode唯一,输出 2

    2. 打出的分数为   4   4  2   2  1   3

    其中2,4出现的次数最多,mode不唯一,升序输出 2  4

    3.打出的分数为   2   2   3   3   3   2

    其中2,3出现的次数最多,但没有其它的分数了,也就是打出的分数每个都是mode,输出 Bad Mushroom.

    其中第三种情况要特别注意一下,还要判断mode出现了几种,上面例子是出现了两种2,3,如果只出现一种,比如打出的分数为 2 2 2 2 2 2,要输出2,不能输出Bad Mushroom,所以要特判一下。

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    typedef long long  ll;
    #define inf 0x3f3f3f3f
    #define mod 7
    #include <math.h>
    #include <queue>
    using namespace std;
    int n,a,s,h[10001],cnt[1000001],tt;
    int main()
    {
        int T,K=0,maxt;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            memset(h,0,sizeof(h));
            maxt=0;
            for(int i=0; i<n; i++)
            {
                scanf("%d",&a);
                s=10000-abs(100-a)*abs(100-a);
                h[s]++;
                maxt=max(maxt,h[s]);
            }
            printf("Case #%d:
    ",++K);
            tt=0;
            for(int i=0; i<=10000; i++)
            {
                if(h[i]&&h[i]==maxt)
                {
                    cnt[tt++]=i;
                }
            }
            if(tt==1)
            {
                printf("%d
    ",cnt[0]);
                continue;
            }
            if(tt*maxt==n)
            {
                printf("Bad Mushroom
    ");
                continue;
            }
            bool zz=false;
            for(int i=0; i<tt; i++)
            {
                if(zz)
                {
                    printf(" %d",cnt[i]);
                }
                else
                {
                    printf("%d",cnt[i]);
                    zz=true;
                }
            }
            printf("
    ");
        }
        return 0;
    }

    我第一次写的方法有点麻烦:

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    typedef long long  ll;
    #define inf 0x3f3f3f3f
    #define mod 7
    #include <math.h>
    #include <queue>
    using namespace std;
    int n,a[1000001],s[1000001],h[10001],sum,cnt[1000001],tt,mm[1000001];
    int main()
    {
        int T,K=0,maxt;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            memset(h,0,sizeof(h));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
                s[i]=10000-abs(100-a[i])*abs(100-a[i]);
                h[s[i]]++;
            }
            printf("Case #%d:
    ",++K);
            sort(s,s+n);
            sum=0;
            maxt=0;
            tt=0;
            for(int i=0;i<=10000;i++)
            {
                  if(h[i])
                  {
                        sum++;
                        mm[tt]=i;
                        cnt[tt++]=h[i];
                        maxt=max(maxt,h[i]);
                  }
            }
            if(sum==1)
            {
                printf("%d
    ",s[0]);
                continue;
            }
            bool ff=false;
            for(int i=0;i<tt;i++)
            {
                if(cnt[i]!=maxt)
                {
                    ff=true;
                    break;
                }
            }
            if(!ff)
            {
                printf("Bad Mushroom
    ");
                continue;
            }
            bool zz=false;
            for(int i=0;i<tt;i++)
            {
                if(cnt[i]==maxt)
                {
                    if(zz)
                    {
                        printf(" %d",mm[i]);
                    }
                    else
                    {
                        printf("%d",mm[i]);
                         zz=true;
                    }
                }
            }
            printf("
    ");
        }
        return 0;
    }
    View Code
     
  • 相关阅读:
    textarea宽度、高度自动适应处理方法
    Table嵌套去掉子table的外边框
    发现原来自己挺能给自己找理由开脱的
    Life is not the amount of breath you take.
    在遍历ResultSet的循环中再执行SQL会发生什么(前提:同一个Statement)
    按月查询数据
    Oracle SQL 判断某表是否存在
    在Python程序中执行linux命令
    在Oracle中十分钟内创建一张千万级别的表
    Redis Sentinel结构 及相关文档
  • 原文地址:https://www.cnblogs.com/zhangmingcheng/p/4328448.html
Copyright © 2011-2022 走看看