• 2014 ACM/ICPC Asia Regional 北京 Online


    G - Grade

    Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushrooms and ask him to grade each mushroom according to its weight. Suppose the weight of a mushroom is w, then it’s grade s is 

    s = 10000 - (100 - w)^2

    What’s more, Ted also has to report the mode of the grade of these mushrooms. The mode is the value that appears most often. Mode may not be unique. If not all the value are the same but the frequencies of them are the same, there is no mode.
    InputThe first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow. 

    The first line of each test cases contains one integers N (1<=N<=10^6),denoting the number of the mushroom. 

    The second line contains N integers, denoting the weight of each mushroom. The weight is greater than 0, and less than 200.OutputFor each test case, output 2 lines. 

    The first line contains "Case #x:", where x is the case number (starting from 1) 

    The second line contains the mode of the grade of the given mushrooms. If there exists multiple modes, output them in ascending order. If there exists no mode, output “Bad Mushroom”.Sample Input
    3
    6
    100 100 100 99 98 101
    6
    100 100 100 99 99 101
    6
    100 100 98 99 99 97
    Sample Output
    Case #1:
    10000
    Case #2:
    Bad Mushroom
    Case #3:
    9999 10000

    这个题实际就是hash查找,单他竟然卡了cin,应该是数据加强了,或者我的算法不是很好
    #include <bits/stdc++.h>
    using namespace std;
    int cnt[10005];
    int main() {
        int T,k=1;
        scanf("%d",&T);
        while(T--){
            memset(cnt,0,sizeof(cnt));
            int n;scanf("%d",&n);
            for(int i=0;i<n;i++){
                int x;scanf("%d",&x);
                cnt[10000-(100-x)*(100-x)]++;
            }
            int ma=INT_MIN;
            for(int i=0;i<=10000;i++)
                ma=max(cnt[i],ma);
            int f=0;
            for(int i=0;i<=10000;i++)
            if(cnt[i]&&cnt[i]<ma){
                f=1;break;
            }
             printf("Case #%d:
    ",k++);
            if(ma<n&&!f)printf("Bad Mushroom
    ");
            else{
                int f1=0;
                for(int i=0;i<=10000;i++){
                    if(cnt[i]==ma){
                        if(f1)printf(" ");
                        printf("%d",i);
                        f1=1;
                    }
                }
                printf("
    ");
            }
        }
        return 0;
    }

    F - Frog

    Once upon a time, there is a little frog called Matt. One day, he came to a river. 

    The river could be considered as an axis.Matt is standing on the left bank now (at position 0). He wants to cross the river, reach the right bank (at position M). But Matt could only jump for at most L units, for example from 0 to L. 

    As the God of Nature, you must save this poor frog.There are N rocks lying in the river initially. The size of the rock is negligible. So it can be indicated by a point in the axis. Matt can jump to or from a rock as well as the bank. 

    You don't want to make the things that easy. So you will put some new rocks into the river such that Matt could jump over the river in maximal steps.And you don't care the number of rocks you add since you are the God. 

    Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.

    InputThe first line contains only one integer T, which indicates the number of test cases. 

    For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9). 

    And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.OutputFor each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.Sample Input

    2
    1 10 5
    5
    2 10 3
    3
    6

    Sample Output

    Case #1: 2
    Case #2: 4

    贪心下就可以了
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1000010;
    int a[N];
    int main() {
        int t,n,m,l,k=1;
        scanf("%d",&t);
        while(t--) {
            scanf("%d%d%d",&n,&m,&l);
            for(int i=0; i<n; i++)
                scanf("%d",&a[i]);
            sort(a,a+n);
            int fr=0,ans=0,pre=-l,now;
            a[n]=m;
            for (int i=0; i <=n; i++) {
                now=a[i];
                int t2=(now-fr)/(l + 1);
                pre+=t2*(l + 1);
                ans+=t2*2;
                if (now-pre>l) {
                    pre=fr+t2*(l+1);
                    fr=now;
                    ans++;
                } else fr=now;
            }
            printf("Case #%d: %d
    ",k++,ans);
        }
        return 0;
    }
    大佬您太强了,还请多多指教哎
  • 相关阅读:
    elementui table组件 eltablecolumn宽度和对应位置总结 width="100"
    vue方法中的方法怎么同步顺序执行_vue方法同步(顺序)执行:async/await使用 , 使用async搭配await实现,ajax同步请求,await函数不能单独使用。
    在vue中进行ElementUI 组件的安装、引入 npm i elementui S
    vue中Promise的使用方法详情
    vue项目中main.js使用方法详解
    vue运行npm run dev报错:‘webpackdevserver‘ 不是内部或外部命令,也不是可运行的程序 npm install webpackdevserver savedev save:将依赖下载,并写入package.json文件(类似maven的pom.xml)dev:当这个依赖仅开发的时候用到,部署的时候不用,就加上dev
    Vue基础5个实用案例
    技巧心得:两台不同型号的路由器组成局域网不用交换机
    读书札记:stdafx.h问题的解决Microsoft Visual Studio 2008之C++
    centos7安装libgdiplus。netcore生成验证码,处理图片
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7254037.html
Copyright © 2020-2023  润新知