题意: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 (构造)的更多相关文章

  1. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  2. Codeforces 353D Queue(构造法)

    [题目链接] http://codeforces.com/contest/353/problem/D [题目大意] 10^6个男女排队,每一秒,如果男生在女生前面,即pos[i]是男生,pos[i+1 ...

  3. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  4. Tea Party CodeForces - 808C (构造+贪心)

    Polycarp invited all his friends to the tea party to celebrate the holiday. He has ncups, one for ea ...

  5. Codeforces.578E.Walking(构造)

    题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\ ...

  6. New Roads CodeForces - 746G (树,构造)

    大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorit ...

  7. Subordinates CodeForces - 737C (树,构造)

    大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...

  8. Serega and Fun Codeforces - 455D || queue

    https://codeforces.com/problemset/problem/455/D 其实方法很多,然而当初一个也想不到... 1.分块,块内用链表维护 修改[l,r]就当成删除第r个元素, ...

  9. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

随机推荐

  1. wordpress 插件 汉化

    http://blog.wpjam.com/article/localizing-a-wordpress-plugin-using-poedit/ 翻译或者说本地化 WordPress 插件和主题可以 ...

  2. 寻找数组中第K大数

    1.寻找数组中的第二大数 using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  3. poj3171 Cleaning Shifts[DP]

    https://vjudge.net/problem/POJ-3171.(有价值的区间全覆盖问题) (lyd例题)朴素DP很好想,$f[i]$表示将右端点从小到大排序后从$L$(要求覆盖的大区间)到第 ...

  4. 【转】Cron表达式简介

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...

  5. 【转】JVM可视化工具插件---Visual GC

    Visual GC是一个Java 内存使用分析与GC收集的可视化工具插件 <插件下载> 一:整个区域分为三部分:spaces.graphs.histogram 1 spaces区域:代表虚 ...

  6. (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令

    (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列3 - 上下文菜单(iContextMenu)(一)右键菜单 上一节说到如 ...

  7. XSS与CSRF攻击

    一.XSS Cross Site Script,跨站脚本攻击.是指攻击者在网站上注入恶意客户端代码,通过恶意脚本对客户端网页进行篡改,从而在用户浏览网页时,对用户浏览器进行控制或者获取用户隐私数据的一 ...

  8. 深入理解java虚拟机 精华总结(面试)(转)

    一.运行时数据区域 3 1.1 程序计数器 3 1.2 Java虚拟机栈 3 1.3 本地方法栈 3 1.4 Java堆 3 1.5 方法区 3 1.6 运行时常量池 4 二. hotspot虚拟机对 ...

  9. Java基础--反射Reflection

    Reflection 反射能在运行时获取一个类的全部信息,并且可以调用类方法,修改类属性,创建类实例. 而在编译期间不用关心对象是谁 反射可用在动态代理,注解解释,和反射工厂等地方. -------- ...

  10. AngularJS:依赖注入

    ylbtech-AngularJS:依赖注入 1.返回顶部 1. AngularJS 依赖注入 什么是依赖注入 wiki 上的解释是:依赖注入(Dependency Injection,简称DI)是一 ...