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 ...
随机推荐
- android 通讯录实现
最近项目需要,于是自己实现了一个带导航栏的通讯录,上代码! 一.数据准备 (1)bean: public class Friend { private String remark; private S ...
- How to debug .NET Core RC2 app with Visual Studio Code on Windows?
Simone Chiaretta (http://codeclimber.net.nz/archive/2016/05/20/How-to-debug-NET-Core-RC2-app-with-Vi ...
- 理解 Neutorn LBaaS - 每天5分钟玩转 OpenStack(120)
Load Balance as a Service(LBaaS)是 Neutron 提供的一项高级网络服务.LBaaS 允许租户在自己的网络中创建和管理 load balancer. load bal ...
- Java:泛型基础
泛型 引入泛型 传统编写的限制: 在Java中一般的类和方法,只能使用具体的类型,要么是基本数据类型,要么是自定义类型.如果要编写可以应用于多种类型的代码,这种刻板的限制就会束缚很多! 解决这种限制的 ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- javaScript笔记
两边符号是tab键上面的那个键,不是单引号 即在sort内置的函数中先将各字符串转化为统一的大写或者小写,再进行比较即可. -------------------------------------- ...
- Conversations is being developed
Development Conversations is being developed on GitHub by a team of volunteers under the lead of pro ...
- Dapper-据说stackoverflow使用的orm
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- bzoj1503--treap
这道题和一般的题目不同,A和S操作要修改所有节点.所以定义基准d,每个节点的工资是它的值+d,这样就能完成所有操作. I k:将值为k-d的节点插入treap A k:将d加上k S k:将d减去k, ...
- entityframework学习笔记--009-使用原生sql语句操作数据
1 使用原生SQL语句更新--Database.ExecuteSqlCommand 假设你有一张如图9-1所示的Payment数据库表. 图9-1 1.1 实体类型: public class Pay ...