HDU-2711 Lost Cows
Lost Cows
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402 Accepted Submission(s): 203
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.
* 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.
#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的更多相关文章
- 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 ...
- hdu 3045 Picnic Cows(斜率优化DP)
题目链接:hdu 3045 Picnic Cows 题意: 有n个奶牛分别有对应的兴趣值,现在对奶牛分组,每组成员不少于t, 在每组中所有的成员兴趣值要减少到一致,问总共最少需要减少的兴趣值是多少. ...
- hdu 2711&&poj2182 Lost Cows (线段树)
从后往前查第一个为0的奶牛肯定应该排在第一个.每次从后往前找到第一个为0的数,这个数应该插在第j位.查找之后,修改节点的值为极大值,当整棵树的最小值不为0的时候查找结束. 至于这种查找修改的操作,再没 ...
- HDU 3045 - Picnic Cows - [斜率DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 It’s summer vocation now. After tedious milking, ...
- HDU 3045 Picnic Cows(斜率优化DP)
Picnic Cows Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 3045 picnic cows(斜率DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 题目大意:有n个数,可以把n个数分成若干组,每组不得小于m个数,每组的价值=除了该组最小值以外每 ...
- 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]$为答案. 然后斜率优化就可以 ...
- [kuangbin带你飞]专题二十 斜率DP
ID Origin Title 20 / 60 Problem A HDU 3507 Print Article 13 / 19 Problem B HDU 2829 Lawr ...
- Graham凸包算法简介
凸包真是一个神奇的算法.. 概念 凸包,我理解为凸多边形 叉积 对于向量AB和向量BC,记向量AB*向量BC = AB * BC * sin ∠ABC,而叉积的绝对值其实就是S△ABC/2 对于平面上 ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- javascript变量,类型 第9节
1.变量,数据类型 <html> <head> <title>变量</title> </head> <body> <h3& ...
- 菜鸟笔记之java中方法使用
N!!!java中无参无返回值方法的使用 1,定义方法 eg: public void show(){ System.out.println("HelloWorld!") } -- ...
- android软件开发之webView.addJavascriptInterface循环渐进【一】
本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gra ...
- 关于C++对汉字拼音的处理——终结篇
以前写过了3个博文,都是关于汉字转拼音的,后来发现都不是很“完美”的解决方案,第一个和第二个利用的unicode编码的范围进行确定汉字的拼音,但是难免有遗漏,这个在后面的实践中发现的,后来第三个方法是 ...
- 项目中logger、message错误信息的配置
申明:在一个项目中必不可少的是Logger和错误信息的配置,现在给出在我们常用的处理方法. —.创建一个ConfigUtils类和他对应的rah.properties文件和Test测试类 Config ...
- 《APUE》第三章笔记(3)
文件共享 UNIX系统支持在不同进程中共享打开的文件,首先先用一幅apue的图来介绍一下内核用于I/O文件的数据结构: 如图所见,一个进程都会有一个记录项,记录项中包含有一张打开文件描述符表,每个描述 ...
- couchDB入门
无意翻到一本新书<CouchDB权威指南> 发现这就是传说中的NoSQL,看排第一的是mangodb,redis有些人说是,有些人说不是. CouchDB的开发很天才,直接可以通过java ...
- mvc3.0ModelFirst生成实体
前沿 这几天想用mvc写点东西,mvc现在自己工作也不用,所以有些生.于是弄点视频研究一下.可能一些经常接触mvc的对这个问题看来,就是小kiss,但是我感觉自己研究出来了还是比较兴奋.在3.0根据模 ...
- Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays
Professor GukiZ and Two Arrays 题意:两个长度在2000的-1e9~1e9的两个序列a,b(无序);要你最多两次交换元素,使得交换元素后两序列和的差值的绝对值最小:输出这 ...
- NOI冲刺计划
省选过了,剩下大概是NOI冲刺了吧.中间还有一大堆诸如会考,CTSC,APIO等东西. 最近先不急着天天刷八中了吧,多在不同网站见一些题,然后再着重提高一下代码准确性.重点把DP这个板块多练习一下,八 ...