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. 我们设想一个长度 ...
随机推荐
- ENTRYPOINT 与 CMD
在Dockerfile中 ENTRYPOINT 只有最后一条生效,如果写了10条,前边九条都不生效 ENTRYPOINT 的定义为运行一个Docker容器像运行一个程序一样,就是一个执行的命令 两种写 ...
- 一次调用cloudera的的API和JSON想到的
JSON的null字段 在我的项目中修改了YARN的资源池,到cloudera中就报错,查询还不报错,但是修改的时候,就报错,大致意思就是信息有异常,“包含了尖括号. 因为通过API+json交互,我 ...
- 洛谷【P1714】切蛋糕
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://www.luogu.org/problemnew/show/P1714 ...
- 异常:java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType
这个是jdK版本的问题的. 本地编译的jar包是1.8的,但是跑jar包的环境jdk版本是1.9的. 升级1.9之后由于jdk当方面的取消了几个jar,所以导致编译起不来. 明天研究一下如何添加jar ...
- MongoDb学习网站
http://www.runoob.com/mongodb/mongodb-window-install.html
- c# 几种singleton 实现
http://csharpindepth.com/Articles/General/Singleton.aspx#introduction 4th在线看 https://www.manning.com ...
- PowerDesignerPDM中搜寻表名或字段名
Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl '当前model '获取当前活 ...
- nginx isis
Nginx+IIS简单的部署 随着互联网项目用户访问量不断上升,单点web服务器是无法满足大型高并发高负载的业务处理的,为了给web服务器做负载均衡方案,打算采用Nginx搭建负载均衡服务器,把用 ...
- 11-02SQLserver基础--字符串函数
数据库の函数 一.内置函数--字符串函数 1.--ASCII 返回字符串的首字母的ASCII编码 select ASCII('ame') select ASCII(xingming)from xues ...
- Struts2 全局结果集-全局result节点设置,package设置abstract=true的实现
转自:https://blog.csdn.net/u013161278/article/details/41855273 如果我们所有的action均有可能跳到相同的页面,则不妨使用全局result. ...