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. 我们设想一个长度 ...
随机推荐
- Python 中的几种矩阵乘法 np.dot, np.multiply, *
使用array时,运算符 * 用于计算数量积(点乘),函数 dot() 用于计算矢量积(叉乘).使用matrix时,运算符 * 用于计算矢量积,函数 multiply() 用于计算数量积. 下面是使用 ...
- 微信小程序 报错Setting data field "variableName" to undefined is invalid.
Setting data field "variableName" to undefined is invalid. 将数据字段“variableName”设置为未定义是无效的. ...
- Ubuntu下部署GitLab-——基于14.04系统
搭建GitLab的目的: 方便公司开发管理代码 GitLab实现的功能: 1.关闭了gitlab的注册功能 2.修改了默认端口 3.汉化 0.前期准备 # 环境 Ubuntu 14.04 root@i ...
- Jmeter & TICK
背景: 本来只是想在将Jmeter的测试结果写入InfluxDB, 但发现从InfluxDB V1.3后开始, 已经不支持Web Admin interface, 才发现InfluxData 搞了 ...
- Js基础之函数
定义函数:我们使用function标签来定义函数 使用函数:JavaScript函数定义完毕是不能自动执行的,需要我们调用或者事件触发,比如点击事件,鼠标事件,键盘事件等. 下面我们以点击事件为例,调 ...
- C# 不使用Task实现的多线程顺序执行
多线程有很好的并发性即无序性,在某些特殊情况下需要用到多线程然而又要使其具备顺序性,这种时候就有了一个特殊的场景那就是多线程顺序执行,在现在VS2015中Task自带了顺序执行的方法,但在此之前的旧项 ...
- 自定义ASP.NET MVC Html辅助方法
在ASP.NET MVC中,Html辅助方法给我们程序员带来很多方便,其重要性也就不言自明.有时候,我们不想重复地写一些HTML代码,或者MS没有提供我们想要的那个HTML标签的Html辅助方法,那么 ...
- VMware:Configuration file was created by a VMware product with more features than this version
Few days ago,I opened the Genesys demo VM by VMware Server 1.0.4 and got an error like this: "C ...
- java反射专题三
一丶调用运行时类中指定的属性 Class clazz = Person.class; //1.获取指定的属性 Field name = clazz.getField("name") ...
- ThinkPad E431按F1后直接进入系统无法进入BIOS
联想的ThinkPad系列笔记本一般是按F1进如BIOS的,但是由于现在联想的笔记本多数都是预装Win 8或者更高版本的系统,所以有时候就没办法直接按F1进去BIOS.其原因是因为Win 8或者更高版 ...