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. PHP如何打造一个高可用高性能的网站呢?

    https://blog.csdn.net/jwq101666/article/details/80162245 1. 说到高可用的话要提一下redis,用过的都知道redis是一个具备数据库特征的n ...

  2. MyEclipse使用总结——将原有的MyEclipse中的项目转成maven项目[转]

    前面一篇文章中我们了解了 在myeclipse中新建Maven框架的web项目 那么如果我们原来有一些项目现在想转成maven项目应该怎么做呢 我收集到了三种思路: 一.新建一个maven项目,把原项 ...

  3. 杂项-SpringBoot-Jasypt:Jasypt(安全框架)

    ylbtech-杂项-SpringBoot-Jasypt:Jasypt(安全框架) 1. 使用jasypt加密Spring Boot应用中的敏感配置返回顶部 1. 本文讲述了在Spring Boot/ ...

  4. iOS开发使用UIScrollView随笔

    1.scrollview滚动到固定偏移量contenOffset - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)anim ...

  5. Lucene 的 Field 域和索引维护

    一.Field 域 1.Field 属性 Field 是文档中的域,包括 Field 名和 Field 值两部分,一个文档可以包括多个 Field,Document 只是 Field 的一个承载体,F ...

  6. java笔试之字符串反转

    写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串. package test; import java.util.Scanner; public class exam04 { public ...

  7. [Swoole系列入门教程 5] UDP协议和demo

    • 客户端服务端没有任何联系 • 指定地址跟端口,不关心消息是否发送成功 • 心跳检测不能影响到客户端• udp建立长连接

  8. 1008-Redo

    关于flag,都立下了 T1 考试的时候就觉得是贪心,但是不会反悔emm…… 于是正解就是一个堆优化可反悔的贪心=.= 每次找前面最小的,于是是小根堆. 我们在交易的时候发现后面的一个可以更优. 于是 ...

  9. 时间格式的时间 转json的时候变成正常的string时间20170519

    public class JsonDateValueProcessor implements JsonValueProcessor { private String format ="yyy ...

  10. Vuejs实战项目三:退出系统功能实现

    1.创建Mockjs接口 method:post url:/user/logout 描述:退出系统 response: { "code": 2000, //状态码 "fl ...