Lost Cows
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11946   Accepted: 7690

Description

N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up for their evening meal, they did not line up in the required ascending numerical order of their brands.

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

* Line 1: A single integer, N

* 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

* Lines
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的更多相关文章

  1. poj2182Lost Cows——树状数组快速查找

    题目:http://poj.org/problem?id=2182 从后往前确定,自己位置之前没有被确定的且比自己编号小的个数+1即为自己的编号: 利用树状数组快速查找,可另外开一个b数组,角标为编号 ...

  2. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  3. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  4. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  5. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  6. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  7. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  8. POJ2186 Popular Cows [强连通分量|缩点]

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31241   Accepted: 12691 De ...

  9. Poj2186Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 De ...

随机推荐

  1. 深入浅出Mybatis系列(一)---Mybatis入门[转]

    最近两年 springmvc + mybatis 的在这种搭配还是蛮火的,楼主我呢,也从来没真正去接触过mybatis, 趁近日得闲, 就去学习一下mybatis吧. 本次拟根据自己的学习进度,做一次 ...

  2. 菜鸟nginx源码剖析数据结构篇(七) 哈希表 ngx_hash_t(下)[转]

    菜鸟nginx源码剖析数据结构篇(七) 哈希表 ngx_hash_t(下) Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.c ...

  3. iOS开发本地推送(iOS10)UNUserNotificationCenter

    1.简介 iOS10之后苹果对推送进行了封装,UNUserNotificationCenter就这样产生了.简单介绍本地推送的使用UserNotifications官方文档说明! 2.简单使用UNUs ...

  4. matlab-选择-循环-函数

    1 选择 3 循环 break 3 函数

  5. Liunx常用命令行(Ubuntu)

    关闭防火墙的命令行: 1. 永久性生效 开启:chkconfig iptables on 关闭:chkconfig iptables off 2. 即时生效,重启后失效 开启:service ipta ...

  6. 深度学习(二十六)Network In Network学习笔记

    深度学习(二十六)Network In Network学习笔记 Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/deta ...

  7. “玲珑杯”ACM比赛 Round #11 B题

    http://www.ifrog.cc/acm/problem/1097?contest=1013&no=1 //LIS的高端写法 #include <iostream> #inc ...

  8. 比特镇步行(Walk)【虚点+bfs+dfs】

    Online Judge:NOIP2016十连测第一场 T3 Label:虚点,bfs,dfs 题目描述 说明/提示 对于100%数据,\(n<=200000\),\(m<=300000\ ...

  9. spring boot项目搭建中遇到的问题

    自己动手搭建一下spring boot的项目,中途遇到了几个问题,在这里记录一下! 一.关于数据库中的表设计的问题 1.设计表的时候一定要添加的两个字段created updated 创建时间与更新时 ...

  10. conda、pip换源以及conda、pip命令比较

    conda换源: conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda ...