CodeForces 141C Queue (构造)
题意:n 个人在排队,然后给出每个人的前面比他身高高的人的数量hi,让你给出一种排列,并给出一种解。
析:首先,hi 小的要在前面,所以先进行排序,然后第一个人的 h1 必须为0,我们可以令身高为 1,然后对于第 i 个人,前面1 ~ i-1 个人中有 hi 个人
比他高,那么就有 i-1-hi 个人不比他高,所以他的身高的最佳情况就是 i - hi。不过这样会覆盖前面那个身高和他相等的人,所以我们把 1 ~ i-1 中所有的
身高比他高的人都加上1,这样就消除了影响。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 3000 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} struct Node{
string name;
int num;
Node() { }
Node(string s, int n) : name(s), num(n) { }
bool operator < (const Node &p) const{
return num < p.num;
}
};
Node a[maxn];
const int det = 100000; int main(){
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i].name >> a[i].num; sort(a, a + n);
if(1 == n && a[0].num){ cout << "-1" << endl; return 0; }
a[0].num = 1;
for(int i = 1; i < n; ++i){
if(a[i].num > i){
cout << "-1" << endl;
return 0;
}
a[i].num = i - a[i].num + 1;
for(int j = 0; j < i; ++j)
if(a[j].num >= a[i].num) ++a[j].num;
}
for(int i = 0; i < n; ++i)
cout << a[i].name << " " << a[i].num + det << endl;
return 0;
}
CodeForces 141C Queue (构造)的更多相关文章
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- Codeforces 353D Queue(构造法)
[题目链接] http://codeforces.com/contest/353/problem/D [题目大意] 10^6个男女排队,每一秒,如果男生在女生前面,即pos[i]是男生,pos[i+1 ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Tea Party CodeForces - 808C (构造+贪心)
Polycarp invited all his friends to the tea party to celebrate the holiday. He has ncups, one for ea ...
- Codeforces.578E.Walking(构造)
题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\ ...
- New Roads CodeForces - 746G (树,构造)
大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorit ...
- Subordinates CodeForces - 737C (树,构造)
大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...
- Serega and Fun Codeforces - 455D || queue
https://codeforces.com/problemset/problem/455/D 其实方法很多,然而当初一个也想不到... 1.分块,块内用链表维护 修改[l,r]就当成删除第r个元素, ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
随机推荐
- C#异步编程(三)内核模式线程同步
其实,在开发过程中,无论是用户模式的同步构造还是内核模式,都应该尽量避免.因为线程同步都会造成阻塞,这就影响了我们的并发量,也影响整个应用的效率.不过有些情况,我们不得不进行线程同步. 内核模式 wi ...
- 学习动态性能表(19)--v$undostat
学习动态性能表 第19篇--V$UNDOSTAT 2007.6.14 本视图监控当前实例中undo空间以及事务如何运行.并统计undo空间开销,事务开销以及实例可用的查询长度. V$UNDOSTAT ...
- Python函数-bool()
bool([x]) 作用: 将x转换为Boolean类型,如果x缺省,返回False,bool也为int的子类: 参数x: 任意对象或缺省:大家注意到:这里使用了[x],说明x参数是可有可无的,如果不 ...
- bzoj 4559 [JLoi2016]成绩比较——拉格朗日插值
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4559 关于拉格朗日插值,可以看这些博客: https://www.cnblogs.com/E ...
- ExtJs中获得当前选中行号(Grid中多选或者是单选)及Grid的反选(取消选中行)
多选,如何获得每行的行号: function getlineNum(){ var sm=titleGird.getSelectionModel(); // 获得grid的SelectionMod ...
- hihoCoder#1121(二分图判定)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Nettle,从这个星期开始由我来完成我们的Weekly. 新年回家,又到了一年一度大龄 ...
- java中i/o练习
总结: FileInputStream fis; int length; while((length=fis.read(b,0,b.length))!=-1){ output.write(b,0,le ...
- MyBatis----延迟加载demo
一:创建数据库脚本drop table project_info; drop table status; create table status( id number(10) primary key, ...
- CSS3新特性详解
本文讲解CSS3相关实用知识点 CSS3相关实用知识点目录 边框设置 颜色设置 背景设置 渐变使用 超出文本设置 阴影设置 CSS3变换设置 过渡设置 动画设置 多列布局 BoxSizing设置 弹性 ...
- c#的日志插件NLog基本使用
本文介绍c#的日志插件NLog 安装插件 创建logger 日志级别 书写日志信息 配置 包装器 布局 安装插件 直接下载插件包 Install-Package NLog.Config 创建logge ...