Lost Cows

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402    Accepted Submission(s): 203

Problem 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
#include<stdio.h>
#define maxn 500004
int a[],s[],n;
struct node
{
int left,right;
int num;
};
node tree[*maxn];
void build(int left,int right,int i)
{
tree[i].left =left;
tree[i].right=right;
tree[i].num =right-left+;
if(tree[i].left ==tree[i].right )
return ;
build(left,(left+right)/,*i);
build((left+right)/+,right,*i+);
}
int insert(int i,int r)
{
tree[i].num--;
if(tree[i].left==tree[i].right)
return tree[i].left ;
if(tree[*i].num>=r)
insert(i*,r);
else
insert(i*+,r-tree[*i].num);
}
int main()
{
int i;
while(~scanf("%d",&n))
{
a[]=;
for(i=;i<=n;i++)
scanf("%d",&a[i]);
build(,n,);
for(i=n;i>=;i--)
s[i]=insert(,a[i]+);
for(i=;i<=n;i++)
printf("%d\n",s[i]); }
return ;
}

HDU-2711 Lost Cows的更多相关文章

  1. POJ 2182 / HDU 2711 Lost Cows(平衡树)

    Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular di ...

  2. hdu 3045 Picnic Cows(斜率优化DP)

    题目链接:hdu 3045 Picnic Cows 题意: 有n个奶牛分别有对应的兴趣值,现在对奶牛分组,每组成员不少于t, 在每组中所有的成员兴趣值要减少到一致,问总共最少需要减少的兴趣值是多少. ...

  3. hdu 2711&&poj2182 Lost Cows (线段树)

    从后往前查第一个为0的奶牛肯定应该排在第一个.每次从后往前找到第一个为0的数,这个数应该插在第j位.查找之后,修改节点的值为极大值,当整棵树的最小值不为0的时候查找结束. 至于这种查找修改的操作,再没 ...

  4. HDU 3045 - Picnic Cows - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 It’s summer vocation now. After tedious milking, ...

  5. HDU 3045 Picnic Cows(斜率优化DP)

    Picnic Cows Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 3045 picnic cows(斜率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 题目大意:有n个数,可以把n个数分成若干组,每组不得小于m个数,每组的价值=除了该组最小值以外每 ...

  7. HDU 3045 Picnic Cows

    $dp$,斜率优化. 设$dp[i]$表示$1$至$i$位置的最小费用,则$dp[i]=min(dp[j]+s[i]-s[j]-(i-j)*x[j+1])$,$dp[n]$为答案. 然后斜率优化就可以 ...

  8. [kuangbin带你飞]专题二十 斜率DP

            ID Origin Title   20 / 60 Problem A HDU 3507 Print Article   13 / 19 Problem B HDU 2829 Lawr ...

  9. Graham凸包算法简介

    凸包真是一个神奇的算法.. 概念 凸包,我理解为凸多边形 叉积 对于向量AB和向量BC,记向量AB*向量BC = AB * BC * sin ∠ABC,而叉积的绝对值其实就是S△ABC/2 对于平面上 ...

  10. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

随机推荐

  1. myeclipse启动报JVM terminated. Exit code=1

    报错信息如图: 解决办法: 删除当前workspaces下文件夹,路径为:%Workspaces%/.metadata/.plugins/org.eclipse.core.runtime

  2. java ,js获取web工程路径

    一.java获取web工程路径 1),在servlet可以用一下方法取得: request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/” ...

  3. String类与Date类的转换

    public class DateTest { public static void main(String[] args) throws ParseException { Date date = n ...

  4. zlib压缩解压示例

    #include <stdio.h> #include <string.h> #include <assert.h> #include "zlib.h&q ...

  5. 入门2:PHP相关的名词解释

    /**宝宝我英语不好,后面注释拼音 请见谅**/ 1.Linux 开源的操作系统,在服务器端用户数量非常大,很多服务器都是使用Linux系统运行的. 相对windows系统来说具有非常完善的用户权限系 ...

  6. CentOS 6.4 通过Yum给Chrome安装Adobe Flash Player

    方法一:安装 Flash Player yum install flash-plugin 安装好后,重新启动chrome,在地址栏输入[chrome://plugins/]确定 Shockware F ...

  7. Ubuntu启动项设置——之update-rc.d 命令使用

    http://blog.csdn.net/typ2004/article/details/38712887 apache2.nginx.redis这些服务安装之后,会随开机启动,当这些服务并不需要时, ...

  8. WPF界面特殊字符处理

          界面XAML不支持< .>.&."等字符. 使用字符实体编码进行替代,以下是pro WPF 4.5的摘要表 Special Character        ...

  9. asp.net mvc 发送邮箱验证码

    public ActionResult Index() { /*第一种,利用Google的smtp来发送邮件*/ SmtpClient client = ); Random Rdm = new Ran ...

  10. caller和callee的区别

    ①.caller caller返回一个函数的引用,这个函数调用了当前的函数. 使用这个属性要注意: 1 这个属性只有当函数在执行时才有用 2 如果在javascript程序中,函数是由顶层调用的,则返 ...