POJ2182Lost Cows
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11946 | Accepted: 7690 |
Description
Regrettably, FJ does not have a way to sort them. Furthermore, he's
not very good at observing problems. Instead of writing down each
cow's brand, he determined a rather silly statistic: For each cow in
line, he knows the number of cows that precede that cow in line that do,
in fact, have smaller brands than that cow.
Given this data, tell FJ the exact ordering of the cows.
Input
* Lines 2..N: These N-1 lines describe the number of cows that
precede a given cow in line and have brands smaller than that cow. Of
course, no cows precede the first cow in line, so she is not listed.
Line 2 of the input describes the number of preceding cows whose brands
are smaller than the cow in slot #2; line 3 describes the number of
preceding cows whose brands are smaller than the cow in slot #3; and so
on.
Output
1..N: Each of the N lines of output tells the brand of a cow in line.
Line #1 of the output tells the brand of the first cow in line; line 2
tells the brand of the second cow; and so on.
Sample Input
5
1
2
1
0
Sample Output
2
4
5
3
1
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b)
#define lowbit(x) ((x) & (-1 * (x))) inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} const int MAXN = + ; int n, num[MAXN], bst[MAXN]; void modify(int p, int k)
{
for(;p <= n;p += lowbit(p))bst[p] += k;
} int ask(int p)
{
int sum = ;
for(;p;p -= lowbit(p))sum += bst[p];
return sum;
} int erfen(int ans)
{
int l = , r = n, mid;
while(l <= r)
{
mid = (l + r) >> ;
if(ask(mid) < ans)l = mid + ;
else r = mid - ;
}
return l;
} int main()
{
read(n);
for(register int i = ;i <= n;++ i) read(num[i]);
for(register int i = ;i <= n;++ i) modify(i, );
for(register int i = n;i >= ;-- i)
{
num[i] = erfen(num[i] + );
modify(num[i], -);
}
for(register int i = ;i <= n;++ i) printf("%d\n", num[i]);
return ;
}
POJ2182
POJ2182Lost Cows的更多相关文章
- poj2182Lost Cows——树状数组快速查找
题目:http://poj.org/problem?id=2182 从后往前确定,自己位置之前没有被确定的且比自己编号小的个数+1即为自己的编号: 利用树状数组快速查找,可另外开一个b数组,角标为编号 ...
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- LeetCode 299 Bulls and Cows
Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...
- [Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- POJ2186 Popular Cows [强连通分量|缩点]
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31241 Accepted: 12691 De ...
- Poj2186Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31533 Accepted: 12817 De ...
随机推荐
- apache配置域名子目录,访问不同子项目
<VirtualHost *:443> DocumentRoot "E:/phpstudy/WWW/nextplus" ServerName local-main.co ...
- vue2.0 使用webpack搭建项目遇到的最搞笑的坑
报错如下: 源码: 然后找了半天没搞明白... 无意中翻看了一下ES6语法规则.. 然后我发现:源代码最后一行要空一行,我心想这什么狗屁规定?MMP
- 2019/10/9 CSP-S 模拟测
T1:最大约数和 给定一个正整数 S,现在要求你选出若干个互不相同的正整数,使得它们的和不大于 S,而且每个数的因数(不包括本身)之和最大.S <= 1000 分析: 其实考完才听他们说是背包, ...
- [洛谷P2472] [SCOI2007]蜥蜴
题目链接: 蜥蜴 题目分析: 一道网络流,先来分析一下问题: 在一个\(r*c\)的图中分布了一些数,其他地方都用\(0\)填充,我们分别从指定的一些数出发,每次可以移动到周围距离为\(d\)以内的数 ...
- 微信小程序chooseImage(从本地相册选择图片或使用相机拍照)
一.使用API wx.chooseImage(OBJECT) var util = require('../../utils/util.js') Page({ data:{ src:"../ ...
- Docker系列(十五):Openshift 简介
1.简单了解openshift相关组件 1.openshift是基于容器技术构建的一个云平台 2.kubernetes是容器编排组件 3.docker是容器引擎驱动组件 4.openshift在Pas ...
- jeecms v9开发资料
开发文档 . 系统架构概述 本系统核心架构为 FreeMarker+hibernate+Spirng 的 mvc 分层架构. 1.1 分层架构模型 img 1.2 数据流转模型 (前端) img . ...
- 阿里云服务器(一)——Nodejs环境配置
最近在阿里云上买了一个轻量应用服务器,想着用来学习一下Nodejs. 64位 配置Nodejs环境: 参考:https://www.runoob.com/nodejs/nodejs-install-s ...
- Netty TCP粘包/拆包问题《二》
1.DelimiterBasedFrameDecoder:是以分隔符作为结束标志进行解决粘包/拆包问题 代码: EchoClient:客户端 /* * Copyright 2012 The Netty ...
- OpenCASCADE动画功能
OpenCASCADE动画功能 eryar@163.com 1.Introduction OpenCASCADE提供了类AIS_Animation等来实现简单的动画功能. 从其类图可以看出,动画功能有 ...