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[];
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=;i<n;i++)
{
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(a[]),cmp);
sum=;
for(int i=;i<n;i++)
{
sum+=pow(0.95,i)*a[i];
}
printf("%.10lf\n",sum);
}
return ;
}
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[],cnt[],tt;
int main()
{
int T,K=,maxt;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(h,,sizeof(h));
maxt=;
for(int i=; i<n; i++)
{
scanf("%d",&a);
s=-abs(-a)*abs(-a);
h[s]++;
maxt=max(maxt,h[s]);
}
printf("Case #%d:\n",++K);
tt=;
for(int i=; i<=; i++)
{
if(h[i]&&h[i]==maxt)
{
cnt[tt++]=i;
}
}
if(tt==)
{
printf("%d\n",cnt[]);
continue;
}
if(tt*maxt==n)
{
printf("Bad Mushroom\n");
continue;
}
bool zz=false;
for(int i=; i<tt; i++)
{
if(zz)
{
printf(" %d",cnt[i]);
}
else
{
printf("%d",cnt[i]);
zz=true;
}
}
printf("\n");
}
return ;
}
我第一次写的方法有点麻烦:
#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[],sum,cnt[],tt,mm[];
int main()
{
int T,K=,maxt;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(h,,sizeof(h));
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
s[i]=-abs(-a[i])*abs(-a[i]);
h[s[i]]++;
}
printf("Case #%d:\n",++K);
sort(s,s+n);
sum=;
maxt=;
tt=;
for(int i=;i<=;i++)
{
if(h[i])
{
sum++;
mm[tt]=i;
cnt[tt++]=h[i];
maxt=max(maxt,h[i]);
}
}
if(sum==)
{
printf("%d\n",s[]);
continue;
}
bool ff=false;
for(int i=;i<tt;i++)
{
if(cnt[i]!=maxt)
{
ff=true;
break;
}
}
if(!ff)
{
printf("Bad Mushroom\n");
continue;
}
bool zz=false;
for(int i=;i<tt;i++)
{
if(cnt[i]==maxt)
{
if(zz)
{
printf(" %d",mm[i]);
}
else
{
printf("%d",mm[i]);
zz=true;
}
}
}
printf("\n");
}
return ;
}
HDU5003:Osu!(签到题)HDU5038:(签到题,题意很坑)的更多相关文章
- hdu5003 Osu!排序实现水题
Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring s ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
->点击<- A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input s ...
- PHP每日签到及连续签到奖励实现示例
数据库字段 num 记录已经连续签到次数 times 记录签到的日期 格式年月日 如 20160101 PHP代码如下 <?php //获取今天的日期 $today = date('Ymd'); ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
- PHP实现类似题库抽题效果
PHP实现类似题库抽题效果 大家好,我顾某人又回来了,最近学了一点PHP,然后就想写个简单小例子试试,于是就写了一个类似于从题库抽题的东西,大概就是先输入需要抽题的数量,然后从数据库中随机抽取题目. ...
- PAT乙级真题及训练题 1025. 反转链表 (25)
PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...
- 啤酒和饮料|2014年蓝桥杯B组题解析第一题-fishers
啤酒和饮料|2014年第五届蓝桥杯B组题解析第一题-fishers 啤酒和饮料 啤酒每罐2.3元,饮料每罐1.9元.小明买了若干啤酒和饮料,一共花了82.3元. 我们还知道他买的啤酒比饮料的数量少,请 ...
随机推荐
- 【MySql】脚本备份数据库
#!/bin/bash #this is a script of mysql backup #Mysql="mysql" #MysqlDump="mysqldump&qu ...
- WHERE 子句用于规定选择的标准。
WHERE 子句 如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句. 语法 SELECT 列名称 FROM 表名称 WHERE 列 运算符 值 下面的运算符可在 WHERE ...
- 【BZOJ】1088: [SCOI2005]扫雷Mine(递推)
http://www.lydsy.com/JudgeOnline/problem.php?id=1088 脑残去想递推去了... 对于每一个第二列的格子,考虑多种情况,然后转移.....QAQ 空间可 ...
- 启动nmon报错while load libncurses.so.5 can not open shared(bit64)
yum install ncurses-devel.i686 也有可能是软件包本身有问题,换一个try
- 模板,BFS
#include <stdio.h> #include <string.h> #include <queue> using namespace std; struc ...
- Foundation框架中的NSNumber对象详解
到目前为止,我们所讨论过的所有数字数据类型,如int型.float型和long型都是Objective-C语言中的基本数据类型,也就是说,它们都不是对象.例如,不能向它们发送消息.然而,有时需要作为对 ...
- 『AngularJS』一点小小的理解
AngularJS 是一个前端的以Javascript为主的MVC框架.与AngularJS相类似的还有EmberJS. 随着时代在进步,各种各样的开发理念与开发框架不断的提出与发展,而就目前来说,除 ...
- PAT 甲级 1024 Palindromic Number
1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- Put queue for MemoryTransaction of capacity 10000 full, consider committing more frequently, increasing capacity or increasing thread count flume capacity 时间数
package com.test; import org.apache.http.*;import org.apache.http.entity.ContentType;import org.apac ...
- 部署本地gitlab
一.gitlab简介 GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能 ...