刷题总结——Throw nails(hdu4393)
题目:
Problem Description
Each player has a single straight runway. And ZL will throw a nail every second end to the farthest player's runway. After the "BOOM", this player will be eliminated. If more then one players are NO.1, he always choose the player who has the smallest ID.
Input
In each case, the first line contains one integer n (1 <= n <= 50000), which is the number of the players.
Then n lines follow, each contains two integers Fi(0 <= Fi <= 500), Si (0 < Si <= 100) of the ith player. Fi is the way can be run in first second and Si is the speed after one second .i is the player's ID start from 1.
Hint
Huge input, scanf is recommended.
Huge output, printf is recommended.
Output
c is the case number start from 1.
The second line output n number, separated by a space. The ith number is the player's ID who will be eliminated in ith second end.
Sample Input
3
Sample Output
1 3 2
Case #2:
4 5 3 2 1
Hint
Hint
The first case:
1st Second end
Player1 100m (BOOM!!)
Player2 100m
Player3 3m
2nd Second end
Player2 102m
Player3 103m (BOOM!!)
3rd Second end
Player2 104m (BOOM!!)
Source
题目:
这道题其实有一个很nb的做法··这里就不提了··网上都有··
首先想到这道题由于严格按淘汰顺序输出肯定要模拟淘汰的过程···但肯定不会是纯模拟···
看到SF偏小,然后由每次淘汰最大我们考虑消除FS中的某个影响··从而利用单调性快速求出最大值··
是不是和NOIP2016蚯蚓很像?
我们将S(因为S<=100)相等的车子塞进同一个有限队列中··按第一关键字F,第二关键字标号排序,然后每次模拟时比较每个队列的对首元素即可····
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
inline int R(){
char c;int f=;
for(c=getchar();c<''||c>'';c=getchar());
for(;c<=''&&c>='';c=getchar()) f=(f<<)+(f<<)+c-'';
return f;
}
priority_queue< pair<int,int> > que[];
int T,n;
int main()
{
//freopen("a.in","r",stdin);
T=R();
for(int a=;a<=T;a++)
{
printf("Case #%d:\n",a);
n=R();int f,s,lim=;
for(int i=;i<=n;i++) f=R(),s=R(),lim=max(lim,s),que[s].push(make_pair(f,-i));
for(int t=;t<n;t++){
int ans,maxx=-,v;
for(int i=;i<=lim;i++){
if(que[i].empty()) continue;
int f=que[i].top().first,id=-que[i].top().second;
if(f+i*t>maxx||(f+i*t==maxx&&id<ans)){
maxx=f+i*t;ans=id,v=i;
}
}
if(t!=n-) printf("%d ",ans);
else printf("%d",ans);
que[v].pop();
}
putchar('\n');
}
return ;
}
刷题总结——Throw nails(hdu4393)的更多相关文章
- hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
...
- leetcode刷题--两数之和(简单)
一.序言 第一次刷leetcode的题,之前从来没有刷题然后去面试的概念,直到临近秋招,或许是秋招结束的时候才有这个意识,原来面试是需要刷题的,面试问的问题都是千篇一律的,只要刷够了题就差不多了,当然 ...
- leecode刷题(8)-- 两数之和
leecode刷题(8)-- 两数之和 两数之和 描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输 ...
- 牛客网Java刷题知识点之Java 集合框架的构成、集合框架中的迭代器Iterator、集合框架中的集合接口Collection(List和Set)、集合框架中的Map集合
不多说,直接上干货! 集合框架中包含了大量集合接口.这些接口的实现类和操作它们的算法. 集合容器因为内部的数据结构不同,有多种具体容器. 不断的向上抽取,就形成了集合框架. Map是一次添加一对元素. ...
- leetcode 刷题记录(java)-持续更新
最新更新时间 11:22:29 8. String to Integer (atoi) public static int myAtoi(String str) { // 1字符串非空判断 " ...
- 基于Typescript和Jest刷题环境搭建与使用
写在前面 前几个月在公司用vue3和ts写项目,想巩固一下基础,于是我想起了去年基于JavaScript和Jest搭建的刷题环境,不如,给它搞个加强版,结合Typescript和Jest 搞一个刷题环 ...
- LeetCode刷题系列
LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...
- ife任务刷题总结(一)-css reset与清除浮动
本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...
- 刷题ING...
我用codeVS刷题.. 努力准备!!
随机推荐
- 轻量级自动化工具 pssh
pssh应用场景 pssh是一个用python编写的可以并发在多台服务器上批量执行命令的工具,它支持文件并行复制,远程并行执行命令,其中文件并行复制是pssh的核心功能,也是同类工具中的一个亮点. 要 ...
- docker基础——关于安装、常用指令以及镜像制作初体验
为什么使用docker docker就是一个轻量级的虚拟机,他解决的是服务迁移部署的时候环境配置问题.比如常见的web服务依赖于jdk.Tomcat.数据库等工具,迁移项目就需要在新的机器重新配置这些 ...
- Spring Security 简介
本文引自:https://blog.csdn.net/xlecho/article/details/80026527 在 Web 应用开发中,安全一直是非常重要的一个方面.安全虽然属于应用的非功能性需 ...
- PLC状态机编程第五篇-状态机自动生成PLC程序
这篇比较简单了,我就直接上图了,不多废话. 一.选择求解器,一定要选择定步长的. 二.右击Chart状态机,出现图上菜单 三.左边红色的勾选择,选择右侧的菜单,然后点击Generate Code按钮, ...
- 【Kaggle】泰坦尼克号
引言 Kaggle官方网站 这是泰坦尼克号事件的基本介绍: 我们需要做的就是通过给出的数据集,通过对特征值的分析以及运用机器学习模型,分析什么样的人最可能存活,并给出对测试集合的预测. 对于Kaggl ...
- C——可变参数
1.要学可变参数,需要先了解C编译器对栈的管理 做个实验可以得到 #include <stdio.h> void func(int a, char b, int c, int d) { i ...
- Codeforces146D 概率DP
Bag of mice The dragon and the princess are arguing about what to do on the New Year's Eve. The drag ...
- vue webpack build 打包过滤console.log()日志
vue cli创建项目在 webpack.prod.conf.js文件 //打包时清除页面中所有打印及debugger断点 new webpack.optimize.UglifyJsPlugin({ ...
- 关于 package.json 和 package-lock.json 文件说明
package.json 在 Node.js 中,模块是一个库或框架,也是一个 Node.js 项目.Node.js 项目遵循模块化的架构,当我们创建了一个 Node.js 项目,意味着创建了一个模块 ...
- Github上最受关注的前端大牛 快来膜拜把!
Github上最受关注的前端大牛 快来膜拜吧! 来源:csdn 发布时间:2014-08-06 阅读次数:4058 14 本文列出了Github上最受关注的10位前端大牛.看看他们负责的项目和提交 ...