hdu5360 Hiking(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Hiking
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 724 Accepted Submission(s): 384
Special Judge
1. he selects a soda not invited before;
2. he tells soda the number of soda who agree to go hiking by now;
3. soda will agree or disagree according to the number he hears.
Note: beta will always tell the truth and soda will agree if and only if the number he hears is no less than li and no larger than ri, otherwise he will disagree. Once soda agrees to go hiking he will not regret even if the final total number fails to meet some soda's will.
Help beta design an invitation order that the number of soda who agree to go hiking is maximum.
The first contains an integer n (1≤n≤105), the number of soda. The second line constains n integers l1,l2,…,ln. The third line constains n integers r1,r2,…,rn. (0≤li≤ri≤n)
It is guaranteed that the total number of soda in the input doesn't exceed 1000000. The number of test cases in the input doesn't exceed 600.
水题,先按li排序,然后不断地塞进优先队列
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
#define mp(X, Y) make_pair(X,Y)
#define pb(X) push_back(X)
#define rep(X, N) for(int X=0;X<N;X++)
#define rep2(X, L, R) for(int X=L;X<=R;X++)
typedef pair<int, int> PII; typedef pair<PII, int> PIII;
priority_queue<PIII, vector<PIII>, greater<PIII> > q;
int f[];
int l[];
int r[];
vector<int> v[]; class hdu5360 {
public:
void solve(std::istream &in, std::ostream &out) {
int n;
in >> n;
for (int i = ; i <= n; i++)in >> l[i];
for (int i = ; i <= n; i++) {
in >> r[i];
if (l[i])v[l[i]].pb(i);
else q.push(mp(mp(r[i], l[i]), i));
}
int num = n;
int ans = ;
int sz = ;
while (n) {
if (q.empty()) {
rep2(i, ans + , n) {
rep(j, v[i].size()) {
f[sz++] = v[i][j];
}
v[i].clear();
}
break;
}
PIII p = q.top();
q.pop();
int y = p.first.first;
int x = p.first.second;
int z = p.second;
f[sz++] = z;
if (x <= ans && y >= ans) {
ans++;
rep(i, v[ans].size()) {
int j = v[ans][i];
q.push(mp(mp(r[j], l[j]), j));
}
v[ans].clear();
}
}
out << ans << endl;
rep(i, sz) {
if (i)out << " ";
out << f[i];
}
out << endl;
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
hdu5360 solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
int n;
in >> n;
for (int i = ; i < n; ++i) {
solver.solve(in, out);
} return ;
}
hdu5360 Hiking(水题)的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- ACM水题
ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...
- CF451C Predict Outcome of the Game 水题
Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...
随机推荐
- 作业:汽车查询--弹窗显示详情,批量删除 php做法(0521)
作业:显示以下界面: 作业要求: 1.查看详细信息,以弹窗的形式显示,使用ajax2.批量删除 一.主页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XH ...
- log4Net使用的四个步骤
第一步.引入程序集,并建立配置文件,放在根目录下config文件夹里.配置文件如下: <?xml version="1.0" encoding="utf-8&quo ...
- DatePickerDialog 控制只选择年月或年或月
etXyLevelDate.setOnTouchListener(selectDateTouchListener()); /** * @desc 选择日期操作 * @param @return * @ ...
- POJ 3525 Most Distant Point from the Sea
http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...
- Unity3D中的工具类
1.时间:Unity提供了Time类,这个类主要用来获取当前的系统时间. Time.time:从游戏开始后开始计时,表示截止目前共运行的游戏时间. Time.deltaTime:获取Update()方 ...
- Altium Designer规则
1.PCB规则 是PCB设计中至关重要的一个环节:保证PCB符合电气要求.机械加工(精度)要求:为自动布局.布线和部分手动布局.布线操作提供依据 为规则检查提供依据,PCB编辑期间,AD会实时地进行一 ...
- Linux系统下C++开发工具-远程终端软件使用
通过前面安装Linux系统介绍,紧接着进入搭建Linux开发环境的第二步,选择C++开发工具,以及必要的客户端软件.从而完整的搭建一个Linux下C++开发的环境,便于初学者在该环境下能够很好的学习. ...
- Best Cow Line (POJ 3617)
题目: 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作. ·从S的头部删除一个字符,加到T的尾部 ·从S的尾部删除一个字符,加到T的尾部 目标是要构 ...
- sicily 1099 Packing Passengers
/**** 题意: 求x,y 满足 x*pa+y*pb=n 同时使得 p = x*ca+y*cb的值最小,若有多种可能,则选择最大x值的组合** 分析: x*pa+y*pb=n 可以用 线性同 ...
- 基于Cordova5.0开发自己定义插件(android)
1.开发插件java部分 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenhmMjE2MjE2/font/5a6L5L2T/fontsize/400/fi ...