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

题目大意:
有编号1-n的n个数字,2<=n<=8000,乱序排列,排序是未知的。对于每个位置的数字,知道排在它前面比它小的数字有多少个。求这个乱序数列的顺序。

解题关键:
在剩下的编号中,第pre[n]+1个数字就是ans[n]

代码如下:

#include <iostream>
using namespace std;
const int N = 8010;
int ans[N], pre[N], num[N];int main() {int n;cin >> n;for (int i = 1; i <= n; i++)num[i] = i;pre[1] = 0;for (int i = 2; i <= n; i++)cin >> pre[i];int k;for (int i = n; i >= 1; i--) {k = 0;for (int j = 1; j <= n; j++) {if (num[j] != -1)k++;if (k == pre[i] + 1) {ans[i] = num[j];num[j] = -1;break;}}}for (int i = 1; i <= n; i++) {cout << ans[i] <<endl;}cout << endl;return 0;
}

poj2182 Lost Cows-暴力相关推荐

  1. POJ2182 Lost Cows(树状数组、二分、倍增)

    Lost Cows 题目链接 Description N (2 <= N <= 8,000) cows have unique brands in the range 1-N. In a ...

  2. 线段树(Segment Tree)

    1.概述 线段树,也叫区间树,是一个完全二叉树,它在各个节点保存一条线段(即"子数组"),因而常用于解决数列维护问题,基本能保证每个操作的复杂度为O(lgN). 线段树是一种二叉搜 ...

  3. POJ2182 HDU2711 Lost Cows【树状数组+线段树】

    Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17113 Accepted: 10664 Descripti ...

  4. [USACO13NOV]Crowded Cows【暴力枚举】

    Pro Luogu3088 Sol 把所有牛的身高按照高度排序方便剪枝.从大到小枚举,如果枚举的这个点满足在范围内且是它的二倍的话,flagflagflag标记一下,记住一定要两个标记,因为范围是两边 ...

  5. hdu4277 暴力

    hdu4277   暴力 USACO ORZ Time Limit : 5000/1500ms (Java/Other)   Memory Limit : 32768/32768K (Java/Oth ...

  6. bzoj 3383: [Usaco2004 Open]Cave Cows 4 洞穴里的牛之四(set+BFS)

    3383: [Usaco2004 Open]Cave Cows 4 洞穴里的牛之四 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 44  Solved ...

  7. bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  8. bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(暴力DFS)

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 774  Solved: 480 ...

  9. Corral the Cows(二分、前缀和、离散化)

    题面:Corral the Cows[牛客] 题目大意 有 nnn 个单位的三叶草,每单位三叶草占据一个 1×11×11×1 的土地,每块土地的位置由其左下角的下标确定,并且下标 xxx 和 yyy ...

  10. NFLS OJ 1162 暴力

    逃离农场 时间限制:1s  内存限制:64M 问题描述 奶牛们正策划一个大胆的逃离农夫John魔掌的计划.它们设法获得了一艘小型充气艇,在夜幕降临时,一队奶牛将会登艇渡过到农场边小河的对岸.这个计划看 ...

最新文章

  1. 隐藏探针显示php版本号,修改版雅黑PHP探针 支持PHP7+(v0.4.7.2)
  2. node搭建的一个应用在前端项目中的可切换接口的代理服务器
  3. 【C#】MD5 小程序编写
  4. ES6基础之——对比两个值是否相等Object.is()
  5. 以太坊怎么注册_以太坊2.0将至,牛市即将到来??
  6. 深度解密Go语言之context
  7. 更改UISearchBar button属性
  8. Android -- 创建XML文件对象及其序列化, pull解析XML文件
  9. 一文了解Redis持久化
  10. Python开发工程师常用开发工具
  11. NUC1154 Vertical Histogram【打印图案】
  12. 零基础学启发式算法(3)-禁忌搜索 (Tabu Search)
  13. 什么是 开发环境、测试环境、生产环境、UAT环境、仿真环境
  14. ESP8285如何做探针盒子
  15. ar5b97无线网卡驱动linux 版下载,atheros ar5b97驱动
  16. 【pwnable.kr】 mistake
  17. 论文阅读: (ECCV 2022) Content-Oriented Learned Image Compression
  18. 几个在线的web代理
  19. 图像处理的相关数学知识
  20. Unity高质量场景打光参考资料

热门文章

  1. 【ArcGIS风暴】ArcGIS获取线段上等间距的点
  2. 史上最全的Visual Studio Code安装C/C++环境,若不行头砍给你。
  3. C语言试题三十九之将s所指字符串中除了下标为奇数、同时ascii值也为奇数的字符外,其余的全都删除;串中剩余字符所形成的一个新串放在t所指的一个数组中。
  4. Android之实现首尾带圆角的多颜色水平条
  5. Android之第一次不显示EditText光标
  6. sqlite数据库的char,varchar,text,nchar,nvarchar,ntext的区别
  7. 北大青鸟s2结业考试机试_重庆北大青鸟「学员心声」任何一次的考试,都是一次珍贵的蜕变...
  8. 老师计算机传帮带工作总结,传帮带工作总结范文
  9. 研究表明:喝酒“上脸”是基因突变,不仅容易老年痴呆,还容易得胃癌
  10. nashorn js 调用 java_从nashorn(JDK 8 JavaScript引擎)调用char []输入参数调用Java函数?...