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. 群晖引导是uefi还是传统模式的识别

     看左下角光标闪不闪,不闪的是uefi,在闪的就是传统

  2. C#获取七牛云token/删除七牛云图片接口

    // 获取七牛token public ApiResponse GetQiniuToken(QiniuToken req) { try { Mac mac = new Mac(req.AccessKe ...

  3. OSG实现利用菲波那契网格(Fibonacci lattice 或 Fibonacci grid)均分球面

    #include<Windows.h> #include<osg/Node> #include<osg/Geode> #include<osg/Group&g ...

  4. 嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem

    Time Limit: 1 Sec Memory Limit: 128 MB Submit: 555 Solved: 273 [Submit][Status][Discuss] Description ...

  5. [转]Sql Server Alter语句

    原文链接:http://www.cnblogs.com/yoolonet/archive/2010/12/10/1884782.html 在修改Sql Server表结构时,常用到Alter语句,把一 ...

  6. 深入浅出 Java Concurrency (11): 锁机制 part 6 CyclicBarrier[转]

    如果说CountDownLatch是一次性的,那么CyclicBarrier正好可以循环使用.它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).所谓屏障点就 ...

  7. 【arc072f】AtCoder Regular Contest 072 F - Dam

    题意 有一个体积为L的水池,有N天 每天早上进水Vi体积的Ti温度的水. 每天晚上可以放掉任意体积的水. 问每天中午,水池满的情况下,水温最高多少. 水的温度只受新加进的谁的影响,对于水\(W1(T1 ...

  8. VS2005+VTK读入点云文件

    使用VTK读入点云文件的基础代码: 头文件: 也许不是全部都用到,为了接下来得工程还是全部都包含进去了 #include "vtkRenderer.h" #include &quo ...

  9. c++ 链接mysql:error LNK2019: 无法解析的外部符号

    使用VS2012编译项目报错如下: error LNK2019: 无法解析的外部符号 _mysql_real_connect@32,该符号在函数 _main 中被引用 error LNK2019: 无 ...

  10. Alpha通道是什么意思,和rgb通道有什么区别

    Alpha通道是什么意思,和rgb通道有什么区别 Alpha通道: 阿尔法通道是一个8位的灰度通道,该通道用256级灰度来记录图像中的透明度信息,定义透明.不透明和半透明区域,其中白表示不透明,黑表示 ...