OJ1604. Country of Fools

1604. Country of Fools

​ Time limit: 1.0 second
​ Memory limit: 64 MB

The chief traffic policeman of the Country of Fools wants to impose a speed limit on the motorway going from the Field of Wonders to the City of Simple Simons. He ordered n speed limit signs. When the order arrived it turned out that the signs had different numbers on them, which showed limits in kilometers per hour. There were k different limits: n1 signs with the first limit, n2 signs with the second limit, etc.; n1 + … + nk = n.

To make the life of drivers not so easy, the chief policeman decided to place the signs on the motorway in such a way that a driver would have to change speed as many times as possible. According to the traffic regulations in the Country of Fools, a speed limitation is valid until the following speed limit sign, and the speed shown in the sign must be observed exactly. For example, if there is the number 60 on the sign, then a car must go until the following sign with the speed of exactly 60 kilometers per hour.

Input

The first line contains the number k of different types of speed limit signs; 1 ≤ k ≤ 10000. The second line contains positive integers n1, …, nk separated with a space. The sum of all ni does not exceed 10000.

Output

Output the order in which the signs must be place on the motorway, in the form of n integers in the range from 1 to k. Assume that a driver must change speed when the car passes by the first sign, irrespective of the initial speed. If there are several solutions, you may output any of them.

Sample

inputoutput
21 2 1 2
2 2
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXNUM = 10010;
struct obstacle
{
	int count;
	int num;
};
obstacle o[MAXNUM];
int ans[MAXNUM][MAXNUM];
bool cmp(obstacle a, obstacle b) {
	return (a.count > b.count);
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> o[i].count;
		o[i].num = i + 1;
	}
	sort(o, o + n, cmp);
	int m = o[0].count;
	int t = 0;
	for (int i = 0; i < n&&t<n; i++) {
		for (int j = 0; j < m;j++) {
			if (o[t].count > 0) {
				ans[i][j] = o[t].num;
				o[t].count--;
			}
			if (o[t].count == 0)t++;
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (ans[j][i] == 0)break;
			else {
				cout << ans[j][i] << " ";
			}
		}
	}
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值