hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
Input
Huge input, scanf is recommended.
Output
Sample Input
Sample Output
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iterator>
#include<utility>
#include<sstream>
#include<iostream>
#include<cmath>
#include<stack>
using namespace std;
const int INF=1000000007;
const double eps=0.00000001;
const int maxn=50005;
int loc[maxn],speed[maxn];
int sum[maxn];
bool vis[maxn];
struct node
{
int now,s,id;
node(int now=0,int s=0,int id=0):now(now),s(s),id(id){}
bool operator < (const node& t) const
{
if(s!=t.s) return s>t.s; //比较速度
if(now!=t.now) return now>t.now; //当前位置
return id<t.id; //id
}
};
vector<node> save;
int main()
{
int T,Case=0;
cin>>T;
while(T--)
{
int N;
cin>>N; for(int i=1;i<=N;i++)
{
scanf("%d%d",&loc[i],&speed[i]);
sum[i]=loc[i]-speed[i]; //由于起始也要淘汰一名选手,所以先减掉,到后面开始模拟时加上即可
}
printf("Case #%d:\n",++Case);
memset(vis,false,sizeof(vis));
int kase=0; //方便打印加的一个标记
for(int i=1;i<=min(N,550);i++) //N可能比550小
{
int choose=-1,Max=-INF;
for(int j=1;j<=N;j++)
{
if(vis[j]) continue;
sum[j]+=speed[j];
if(Max<sum[j]) Max=sum[j],choose=j;
}
vis[choose]=true;
if(kase++) printf(" ");
printf("%d",choose);
}
save.clear();
for(int i=1;i<=N;i++) if(!vis[i]) save.push_back(node(sum[i],speed[i],i)); // 剩余的选手
sort(save.begin(),save.end());
for(int i=0;i<save.size();i++)
{
if(kase++) printf(" ");
printf("%d",save[i].id);
}
printf("\n");
}
return 0;
}
hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)的更多相关文章
- HDU 4393 Throw nails
Throw nails Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 刷题总结——Throw nails(hdu4393)
题目: Problem Description The annual school bicycle contest started. ZL is a student in this school. H ...
- HDU 4393 Throw nails(贪心加模拟,追及问题)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115361#problem/D 题意大致是:给出最多50000个人,拥有最初速度 ...
- G - Throw nails
来源hde4393 The annual school bicycle contest started. ZL is a student in this school. He is so boring ...
- hdu 4393 Throw nails(STL之优先队列)
Problem Description The annual school bicycle contest started. ZL is a student in this school. He is ...
- 【HDOJ】4393 Throw nails
水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...
- HDU 4393 Throw nails(优先队列)
优先队列的应用 好坑,好坑,好坑,重要的事情说三遍! #include<iostream> #include<cstdio> #include<cstring> # ...
- 在线判题 (模拟)http://202.196.1.132/problem.php?id=1164
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #de ...
- 【noip模拟赛4】找啊找啊找BF 拓扑排序
描述 sqybi上次找GF的工作十分不成功,于是依旧单身的他在光棍节前的某天突发奇想,要给自己找一个BF(这里指的是男性的好朋友……),这样既可以和人分享内心的压抑(路人甲:压抑还分享么……),也可以 ...
随机推荐
- 解决Struts2.2.20版本的标签不支持style属性的问题
我先把Exception错误信息贴出来:org.apache.jasper.JasperException: /WEB-INF/jsp/topicAction/addUI.jsp (line: 40, ...
- Subsets II 解答
Question Given a collection of integers that might contain duplicates, nums, return all possible sub ...
- Linux权限管理(笔记)
权限管理:r: w:x: 三类用户:u: 属主g: 属组o: 其它用户 chown: 改变文件属主(只有管理员可以使用此命令)# chown USERNAME file,... -R: 修改目录 ...
- qt反走样(简选)
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #qt反走样(简选) #概念 """ ...
- xcode 执行时模拟器不可选的问题
好久没写博客了,上一次是什么时候都想不起来了. 之前总认为脑袋记住了,用过了就能够了,干嘛要写博客,简直浪费时间.事实上没事写写博客优点还是挺多的.这样既能够对自己用过的和学到的东西做一个总结,也能提 ...
- [React] Styling a React button component with Radium
React's inline styles allow components to stand on their own by not requiring any external CSS. Howe ...
- javascript 切换动画
function startMove(obj, json, fn) { clearInterval(obj.timer); obj.timer = setInterval(function() { v ...
- jquery简单切换插件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- doT.js 声明
// 模板引擎配置项 var tmplOptions = { evaluate: /\{\{([\s\S]+?\}?)\}\}/g, interpolate: /\{\{=([\s\S]+?)\}\} ...
- 动态设置Head的Title、Descrption
HtmlMeta desc = new HtmlMeta(); desc.Name = "Description"; desc.Content = strTitle.ToStrin ...