AC日记——蓬莱山辉夜 codevs 2830
在幻想乡中,蓬莱山辉夜是月球公主,居住在永远亭上,二次设定说她成天宅在家里玩电脑,亦称NEET姬
一天,她要她帮忙升级月球的网络服务器,应为注册用户过多(月兔和地球上的巫女都注册了……),所以作为代理管理员(俗称网管)的她,非常蛋疼。
注册用户格式:
TouhouMaiden 2004 200
其中前面的Touhoumaiden是预设,不做更改,第一个数是标识,第二个数是每次接受信息访问的间隔用时。
你要做的事,就是给定一群用户及n,求出这n次信息访问中,访问到了谁?
presented by Izayoi sakuya
以题目预设格式输入,另起一行以‘#’结束,在其一行输入n
n行,每行输出第行次后,信息访问到了谁?若在一个时间有若干少女被访问到,输出字典序最小的那位少女的标识
TouhouMaiden 2004 200
TouhouMaiden 2005 300
#
5
2004
2005
2004
2004
2005
标识和每次信息访问间隔均在integer内,n<=10000
原本是要用到堆,但深搜+时间即可搞定
数据有点少但也都够变态了
思路:
手写堆模拟。。
恶心简直;
把所有的用户名和访问间隔记录下来
然后我们就可以开始模拟了
先排序
把所有的人第一顺序是时间间隔的大小
第二顺序是用户名的字典序
然后从一个人开始,把他的n次访问都入堆
然后开始从第2个人的循环遍历
把每个人的n次访问都入堆
每入堆一次都伴随着另一个数据的出堆
堆里个数维持在n个
然后,当now的时间大于top的时间则出堆
好吧,思路说的不是很明白,看代码
来,上代码:
#include <cstdio>
#include <iostream>
#include <algorithm> using namespace std; struct node {
int name,now,times;
};
struct node pos[],cur_; class T_heap {
private:
int n;
struct node heap[]; public:
void up(int now)
{
if(now<=) return ;
int next=now>>;
if(heap[now].now!=heap[next].now)
{
if(heap[now].now>heap[next].now)
{
swap(heap[now],heap[next]);
up(next);
}
}
else
{
if(heap[now].name>heap[next].name)
{
swap(heap[now],heap[next]);
up(next);
}
}
} void down(int now)
{
int next=now,lc=now<<,rc=now<<|;
if(lc<=n)
{
if(heap[lc].now!=heap[next].now)
{
if(heap[lc].now>heap[next].now)
{
next=lc;
}
}
else
{
if(heap[lc].name>heap[next].name)
{
next=lc;
}
}
}
if(rc<=n)
{
if(heap[rc].now!=heap[next].now)
{
if(heap[rc].now>heap[next].now)
{
next=rc;
}
}
else
{
if(heap[rc].name>heap[next].name)
{
next=rc;
}
}
}
if(next!=now)
{
swap(heap[next],heap[now]);
down(next);
}
} void qush(struct node cur_)
{
heap[++n]=cur_;
up(n);
} void pop()
{
heap[]=heap[n--];
down();
} struct node top()
{
return heap[];
}
};
class T_heap heap; int num,n; char flag[]; bool cmp(struct node som,struct node som_)
{
if(som.times!=som_.times) return som.times<som_.times;
else return som.name<som_.name;
} int main()
{
cin>>flag;
while(flag[]=='T')
{
cin>>pos[++num].name;
cin>>pos[num].times;
cin>>flag;
}
cin>>n;
sort(pos+,pos+num+,cmp);
for(int j=;j<=n;j++)
{
pos[].now=pos[].times*j;
heap.qush(pos[]);
}
for(int i=;i<=num;i++)
{
for(int j=;j<=n;j++)
{
pos[i].now=pos[i].times*j;
cur_=heap.top();
if(cur_.now!=pos[i].now)
{
if(pos[i].now<cur_.now)
{
heap.pop();
heap.qush(pos[i]);
}
else break;
}
else
{
if(cur_.name>pos[i].name)
{
heap.pop();
heap.qush(pos[i]);
}
else break;
}
}
}
for(int i=n;i>=;i--)
{
pos[i]=heap.top();
heap.pop();
}
for(int i=;i<=n;i++) printf("%d\n",pos[i].name);
return ;
}
AC日记——蓬莱山辉夜 codevs 2830的更多相关文章
- AC日记——楼房 codevs 2995
2995 楼房 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 地平线(x轴)上有n个矩(lou ...
- AC日记——传话 codevs 1506 (tarjan求环)
1506 传话 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 一个朋友网络,如果a认识b,那么如果a第 ...
- AC日记——绿色通道 codevs 3342
3342 绿色通道 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description <思远高考绿色通道&g ...
- AC日记——苹果树 codevs 1228
1228 苹果树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 在卡卡的房子外面,有一棵 ...
- AC日记——刺激 codevs 1958
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description saffah的一个朋友S酷爱滑雪,并且追求刺激(exitement,由于刺激 ...
- AC日记——红与黑 codevs 2806
2806 红与黑 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 有一个矩形房间,覆盖正方形瓷 ...
- AC日记——热浪 codevs 1557 (最短路模板题)
1557 热浪 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...
- AC日记——字典 codevs 4189
4189 字典 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description 最经,skyzhong得到了 ...
- AC日记——开关灯 codevs 1690
开关灯 思路: 线段树: bool懒标记维护: 更新区间时是区间总值减去当前值: 来,上代码: #include <cstdio> #include <cstring> #in ...
随机推荐
- System.arraycopy()和Arrays.copyOf()的区别
先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...
- 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇三:批量处理后的txt文件入库处理
篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...
- MyCat源码分析系列之——BufferPool与缓存机制
更多MyCat源码分析,请戳MyCat源码分析系列 BufferPool MyCat的缓冲区采用的是java.nio.ByteBuffer,由BufferPool类统一管理,相关的设置在SystemC ...
- iOS 保存、读取与应用状态
固化 对于大多数iOS应用,可以将其功能总结为:提供一套界面,帮助用户管理特定的数据.在这一过程中,不同类型的对象要各司其职:模型对象负责保存数据,视图对象负责显示数据,控制器对象负责在模型对象与视图 ...
- JS性能优化
1.不要在同一行声明多个变量. 2.请使用 ===/!==来比较true/false或者数值 3.使用对象字面量替代new Array这种形式 4.不要使用全局函数. 5.Switch语句必须带有de ...
- C# 复制指定节点的所有子孙节点到新建的节点下
XML结构: 新建一个mask_list节点,一个procedure节点,将上面的mask_list和procedure节点的所有子孙节点添加到新建的mask_list和procedure节点 Xml ...
- Linux下安装Redis
1. 下载最新版本的Redis源代码: 命令:wget http://download.redis.io/redis-stable.tar.gz 2. 解压并编译 命令:tar xzf redis-s ...
- Spring 实现数据库读写分离
随着互联网的大型网站系统访问量的增高,数据库访问压力方面不断的显现而出,所以许多公司在数据库层面采用读写分离技术,也就是一个master,多个slave.master负责数据的实时更新或实时查询,而s ...
- MySQL时间分组查询
表TESTER 字段:id -- INT date -- TIMESTAMP 1.如何按年.月.日分组查询? select DATE_FORMAT(date,'%Y-%m-%d') time, ...
- GJM : Unity3D HIAR -【 快速入门 】 四、创建 Hello World
创建 Hello World 本文将介绍如何在 Windows 系统下,使用 HiAR SDK 创建一个简单的 AR 应用.在开始之前,请先完成下列准备工作: 注册 HiAR 帐户 获取 AppKey ...