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[];
int main() {
int T,k=;
scanf("%d",&T);
while(T--){
memset(cnt,,sizeof(cnt));
int n;scanf("%d",&n);
for(int i=;i<n;i++){
int x;scanf("%d",&x);
cnt[-(-x)*(-x)]++;
}
int ma=INT_MIN;
for(int i=;i<=;i++)
ma=max(cnt[i],ma);
int f=;
for(int i=;i<=;i++)
if(cnt[i]&&cnt[i]<ma){
f=;break;
}
printf("Case #%d:\n",k++);
if(ma<n&&!f)printf("Bad Mushroom\n");
else{
int f1=;
for(int i=;i<=;i++){
if(cnt[i]==ma){
if(f1)printf(" ");
printf("%d",i);
f1=;
}
}
printf("\n");
}
}
return ;
}

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=;
int a[N];
int main() {
int t,n,m,l,k=;
scanf("%d",&t);
while(t--) {
scanf("%d%d%d",&n,&m,&l);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
int fr=,ans=,pre=-l,now;
a[n]=m;
for (int i=; i <=n; i++) {
now=a[i];
int t2=(now-fr)/(l + );
pre+=t2*(l + );
ans+=t2*;
if (now-pre>l) {
pre=fr+t2*(l+);
fr=now;
ans++;
} else fr=now;
}
printf("Case #%d: %d\n",k++,ans);
}
return ;
}

最新文章

  1. Leetcode: Sequence Reconstruction
  2. Bootstrap学习笔记系列7-----Bootstrap简单背景CSS及其他辅助类
  3. SilverlightERP&amp;CRM源码(可用于开发基于Silverlight的CRM,OA,HR,进销存等)
  4. 将STM32的标准库编译成lib
  5. Socket 之 API函数介绍
  6. perl学习(10) 字符串处理函数和排序
  7. UIButton UIImage 用法分析
  8. 查增删改MySQL数据库固定模式
  9. 实用css小技巧
  10. 基于哈夫曼编码的文件压缩(c++版)
  11. 【php】下载站系统Simple Down v5.5.1 xss跨站漏洞分析
  12. (转)Golang--使用iota(常量计数器)
  13. win10安装MongoDB提示 the domain,user name and/or password are incorrect. Remember to use &quot;.&quot; for the domain if the account is on the local machine.
  14. hive启动方式
  15. Selenium 15: How to Run Parallel Tests Using Selenium Grid and JUnit
  16. C#的Lamda表达式_匿名函数
  17. intel32指令中文版
  18. 第一步 使用sencha touch cmd 4.0 创建项目、打包(加入全局变量、公用类、自定义扩展、资源文件)
  19. bzoj 1143: [CTSC2008]祭祀river / 2718: [Violet 4]毕业旅行 -- 二分图匹配
  20. LVS-net

热门文章

  1. 日常博客-png,jpeg,gif图片
  2. Android WiFi使用记录
  3. Android程序初体验
  4. mysql IF语句使用
  5. static心得
  6. 使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”
  7. shiro 配置拦截规则之后css和js等失效
  8. 网络大牛如何回答Chrome的15个刁钻面试题?
  9. 用dfs求联通块(UVa572)
  10. JavaScript异步仿同步(控制流)的实现