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:\n",k++);
        if(ma<n&&!f)printf("Bad Mushroom\n");
        else{
            int f1=0;
            for(int i=0;i<=10000;i++){
                if(cnt[i]==ma){
                    if(f1)printf(" ");
                    printf("%d",i);
                    f1=1;
                }
            }
            printf("\n");
        }
    }
    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\n",k++,ans);
    }
    return 0;
}
时间: 2024-07-31 01:54:08

2014 ACM/ICPC Asia Regional 北京 Online的相关文章

hdu 5038 Grade(简单模拟求解)2014 ACM/ICPC Asia Regional 北京 Online

Grade                                                                     Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives h

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu 5008(2014 ACM/ICPC Asia Regional Xi&#39;an Online ) Boring String Problem(后缀数组&amp;二分)

Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 219    Accepted Submission(s): 45 Problem Description In this problem, you are given a string s and q queries. For each que

poj 5024&amp;&amp;&amp;2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)

http://acm.hdu.edu.cn/showproblem.php?pid=5024 分析:预处理每个点在八个方向的射线长度,再枚举八种L形状的路,取最大值. 注意题意是求一条最长路,要么一条直线,要么只有一个90角,即L型.其实直线就是L形的一个方向长度为0. 代码: #include<iostream> #include<map> #include<cstdio> #include<string> #include<cstring>

2014 ACM/ICPC Asia Regional Xi&#39;an Online

03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色.三种.四种...o[]种的位置. 离散化之后,可以边走边记录某个数最后一个出现的位置,初始为-1,而所要求的位置就等于 if(last[a[i]]==-1) 该数没有出现过,num[i][1] = i,num[i][j+1] = num[i-1

HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP

Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description After eating food from Chernobyl,

2014 ACM/ICPC Asia Regional Xi&#39;an Online(HDU 5007 ~ HDU 5017)

题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Sony” 就输出“SONY DAFA IS GOOD!” ,大小写敏感. 思路 : 字符串查找,水题. 1 #include <string.h> 2 #include <stdio.h> 3 #include <iostream> 4 5 using namespace st

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;