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元. 我们还知道他买的啤酒比饮料的数量少,请 ...
随机推荐
- C++ const关键字修饰引用
//const修饰引用的两种用法 #include<iostream> using namespace std; struct Teacher{ ]; int age; }; void S ...
- 解决mac休眠睡眠异常耗电方法
备忘
- 图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)
图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式显示的计算机操作用户界面. 与早期计算机使用的命令行界面相比,图形界面对于用户来说在视觉 ...
- Jhipster token签名异常——c.f.o.cac.security.jwt.TokenProvider : Invalid JWT signature.
背景,jHipster自动生成的springBoot和angularJs前后台端分离的项目.java后台为了取到当前登录者的信息,所以后台开放了 MicroserviceSecurityConfigu ...
- systemd新的系统管理方案
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html http://www.ruanyifeng.com/blog ...
- php 将一个字符串分割为组成它的字符
问: php里如何将一个字符串分割为组成它的字符? 比如hello -> [h, e, l, l, o] 以下有三种方法: 这是需要被分割的字符串: $str = 'Hello小样'; ...
- 概览C++之const
1.C语言中const与 C++中的const void main() { const int a = 10; int *p = (int*)&a; *p = 20; printf(" ...
- 论坛模块_版块管理_增删改查&实现上下移动
论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private St ...
- iOS开发之--实现倒计时显示时分秒
这段时间写公司的一个外包项目,需要用到倒计时:需要显示时分秒,通过在网上搜集资料,找到了2中方法,我把这两种方法结合起来,可以很好的满足这个需求: 1.创建一个类继承自UIlabel,用来展示时分秒的 ...
- CentOS 6.5 配置IP地址的三种方法
1.自动获取IP地址虚拟机使用桥接模式,相当于连接到物理机的网络里,物理机网络有DHCP服务器自动分配IP地址.#dhclient 自动获取ip地址命令#ifconfig 查询系统里网卡信息,ip地址 ...