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元. 我们还知道他买的啤酒比饮料的数量少,请 ...
随机推荐
- 你有自己的Web缓存知识体系吗?
赵舜东 江湖人称赵班长,曾在武警某部负责指挥自动化的架构和运维工作,2008年退役后一直从事互联网运维工作.曾带团队负责国内某电商的运维工作,<saltstack入门与实践>作者,某学院高 ...
- PHP Global定义全局变量使用说明
Global是php中一个比较特殊的命令,大家直接叫他超级全局变量了,下面我来介绍我今天在使用Global定义全局学习笔记了 很不习惯PHP中的变量作用域,PHP中函数变量和全局是完全隔绝的,也就 ...
- e2fsprogs 移植
e2fsprogs是用维护ext2,ext3和ext4文件系统的工具程序集.检测和修复文件系统,需要用到其中的fsck, ext2fs等工具, 由于开发板上没有,重新制作文件系统又比较麻烦.所以就需要 ...
- 【BZOJ】1693: [Usaco2007 Demo]Asteroids(匈牙利)
http://www.lydsy.com/JudgeOnline/problem.php?id=1693 裸匈牙利.. #include <cstdio> #include <cst ...
- digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 Intr ...
- 求出每个team粉丝数最多的3个国家
有这么个表 fans(team,nationality,fanCount) 'Barcelona','Germany',12000'Barcelona','Spain',18000'Barcelona ...
- uva 707(记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21261 思路:此题需要记忆化搜索,dp[x][y][t]表示当前状 ...
- 使用typescript开发react应用
初始化 mkdir project-dir cd project-dir yarn init -y 安装依赖 yarn add react react-dom yarn add -D typescri ...
- Git------Commit和Push的区别
转载:http://wenda.so.com/q/1435946424728324?src=140 git作为支持分布式版本管理的工具,它管理的库(repository)分为本地库.远程库. git ...
- zookeeper两台内网服务器彼此调不到服务的问题。
Start NettyClient /172.20.11.52 connect to the server /172.20.11.52:20881, dubbo version: 2.5.3, cur ...