Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9669 | Accepted: 6228 |
Description
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
* 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
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 跟fzu月赛的一道题很像,当时是从前往后找,现在应该是从后往前找,第i个数应是原顺序序列中的第rcd[i]+1小的数
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<stack>
using namespace std;
const int inf=1<<25;
int n;
int rcd[10000];
void in_put()
{
cin>>n;
for(int i=2;i<=n;++i)
cin>>rcd[i];
}
void solve()
{
int i,j;
stack<int>s;
int num[10000];
for(i=0;i<=n;++i) num[i]=i;
for(i=n;i>=2;i--){//从后往前找1 2 3 4...n中的第n小的数
int cnt=0;
for(j=1;j<=n;++j){
if(num[j]!=inf) cnt++;
if(cnt==rcd[i]+1) break;
}
s.push(num[j]);
num[j]=inf;//找到一个后标记为大值inf
}
for(int i=1;i<=n;++i) if(num[i]!=inf) {s.push(i);break;}//把第一个也压入栈
while(!s.empty()){
cout<<s.top()<<endl;
s.pop();
}
}
int main()
{
in_put();
solve();
return 0;
}
Lost Cows的更多相关文章
-
[LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
-
POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
-
POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
-
LeetCode 299 Bulls and Cows
Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...
-
[Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
-
【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
-
POJ2186 Popular Cows [强连通分量|缩点]
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31241 Accepted: 12691 De ...
-
Poj2186Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31533 Accepted: 12817 De ...
-
[poj2182] Lost Cows (线段树)
线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...
-
【POJ3621】Sightseeing Cows
Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8331 Accepted: 2791 ...
随机推荐
-
机器学习实战4:Adaboost提升:病马实例+非均衡分类问题
Adaboost提升算法是机器学习中很好用的两个算法之一,另一个是SVM支持向量机:机器学习面试中也会经常提问到Adaboost的一些原理:另外本文还介绍了一下非平衡分类问题的解决方案,这个问题在面试 ...
-
安装 SQLManagementStudio_x86_CHS(SQL Server Management Studio) 老提示重启的解决办法
安装 SQL Server Management Studio(SQLManagementStudio_x86_CHS)时,检测时不通过,提示重启电脑,我以为她安装了什么心软件没有重启:所以重启了电脑 ...
-
WinDbg调试命令汇总
一. 1. !address eax 查看对应内存页的属性 2. vertarget 显示当前进程的大致信息 3 !peb 显示process Environment Block 4. lmvm 可以 ...
-
清理300多台MySQL数据库的过期binlog日志
早晨睡梦中,被 on-call了,说磁盘报警,赶紧起来打开email,收到上百封email报警,数据库磁盘不够了,查询了原因 [xxx@xxxx cacti]$ ssh xxxx "df - ...
-
Redis深入之数据结构
Redis主要数据结构 链表 Redis使用的C语言并没有内置这样的数据结构,所以Redis构建了自己的链表实现.列表键的底层实现之中的一个就是链表,一个列表键包括了数量比較多的元素,列表中包括的元素 ...
-
Collection和Map的默认扩容参数
初始大小:调用无参构造函数时默认的容量 加载因子:超过 (当前容量*加载因子) 时会进行扩容 扩容因子:扩容时增加的容量为 (当前容量*扩容因子) 容器 初始容量 ...
-
什么是HTML?HTML5是什么?HTML5有那些优势和特性?
一.什么是HTML 在了解html5之前,首先要说一下html语言,尽管是更新后的5,但很多的地方还是保留了html的优势. HTML是HyperText Markup Language超级文本标记语 ...
-
k8s调度器、预选策略及调度方式
一.k8s调度流程 1.(预选)先排除完全不符合pod运行要求的节点2.(优先)根据一系列算法,算出node的得分,最高没有相同的,就直接选择3.上一步有相同的话,就随机选一个 二.调度方式 1.no ...
-
Redis消息通知(任务队列和发布订阅模式)
Redis学习笔记(十)消息通知(任务队列和发布订阅模式) 1. 任务队列 1.1 任务队列的特点 任务队列:顾名思义,就是“传递消息的队列”.与任务队列进行交互的实体有两类,一类是生产者(produ ...
-
Java基础-面向接口(interface)编程
Java基础-面向接口(interface)编程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.接口的概念 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的“类 ...