HDU-2711 Lost Cows

时间:2022-10-07 15:15:30

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
 
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 &sol; 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&lpar;斜率优化DP&rpar;

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

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

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

  4. HDU 3045 - Picnic Cows - &lbrack;斜率DP&rsqb;

    题目链接: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. &lbrack;kuangbin带你飞&rsqb;专题二十 斜率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. CSS3里的常用选择器总结

    选择器       属性选择器:  img[src="images/2.jpg"]               开头匹配:  a[href ^="page/"] ...

  2. 【hihocoder 1257 Snake Carpet】构造

    2015北京区域赛现场赛第4题. 题面:http://media.hihocoder.com/contests/icpcbeijing2015/problems.pdf OJ链接:http://hih ...

  3. iOS TableView的分割线

    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparato ...

  4. powerdesign

  5. 单元测试系列之八:Sonar 数据库表关系整理一(续)

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 简介:Sonar平台是目前较为流行的静态代码扫描平台,为了便于使用以及自己二次开发,有必要对它的数据库结构进行学习 ...

  6. &lbrack;mybatis-spring&rsqb;sqlSessionFactoryBean

    在mybatis中,SqlSessionFactory由SqlSessionFactoryBuilder创建. 在mybatis-spring中,是由SqlSessionFactoryBean创建的. ...

  7. Solr学习之一 --------环境搭建

    一.准备工具 下载Solr,以目前最新版solr-6.1.0为例 准备servlet容器,Tomcat,Jetty,Resin之类.以Tomcat7为例   二.开始动手 将solr解压出来,在sol ...

  8. 20145326 《Java程序设计》课程总结

    每周读书笔记链接汇总 20145326第1周学习总结 20145326第2周学习总结 20145326第3周学习总结 20145326第4周学习总结 20145326第5周学习总结 20145326第 ...

  9. golang plugin的依赖问题

    golang plugin的依赖问题 此文中涉及的plugin运行环境为mac 10.14,go版本为1.11 主要是想讨论一下插件依赖的第三方库的问题. 例子是在https://github.com ...

  10. jeesite介绍及链接

    https://github.com/thinkgem/jeesite   (需FQ) JeeSite 是一个企业信息化开发基础平台,Java企业应用开源框架,Java EE(J2EE)快速开发框架, ...