Code-forces 491-A 水题

版权声明:博客作者为blue bear,严禁他人在未经作者同意下进行商用转载 https://blog.csdn.net/weixin_44354699/article/details/88232914

题面

Hiking club “Up the hill” just returned from a walk. Now they are trying to remember which hills they’ve just walked through.

It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the sea level. On the first day they’ve traveled from the first stop to the second stop, on the second day they’ve traveled from the second to the third and so on, and on the last day they’ve traveled from the stop N - 1 to the stop N and successfully finished their expedition.

They are trying to find out which heights were their stops located at. They have an entry in a travel journal specifying how many days did they travel up the hill, and how many days did they walk down the hill.

Help them by suggesting some possible stop heights satisfying numbers from the travel journal.

Input
In the first line there is an integer non-negative number A denoting the number of days of climbing up the hill. Second line contains an integer non-negative number B — the number of days of walking down the hill (A + B + 1 = N, 1 ≤ N ≤ 100 000).

Output
Output N space-separated distinct integers from 1 to N inclusive, denoting possible heights of the stops in order of visiting.
Examples

样例

intput output
0
1
2 1
2
1
1 3 4 2

题意分析

大意就是有一个人爬山,给了你上山的天数和下山的天数,然后让你用
(1~N) 数列模拟每一天的高度。
(N=上山天数+下山天数+1)

那么我们就可以分成两种情况:

  1. 上山天数为0,此时每天都下山,只需要从n自减到1即可
  2. 上山天数不为0,那就是上山与下山两段,解法不唯一,这里说下我的思路,预留下山的的高度H=下山天数,然后从H+1的高度上山然后自增至上山天数后从H高度自减即可。

代码

#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
int main(){
 	int up,down,n,f,a[100005],i;
	scanf("%d%d",&up,&down);
	n=up+down+1;
	if(up>0){
		a[0]=down+1;
		for(i=1;i<=up;i++){
			a[i]=a[i-1]+1;
		}
		a[i++]=a[0]-1;
		for(;i<n;i++){
			a[i]=a[i-1]-1;
		}
	}else{
		a[0]=n;
		for(i=1;i<n;i++){
			a[i]=a[i-1]-1;
		}
	}
	printf("%d",a[0]);
	for(i=1;i<n;i++)	printf(" %d",a[i]);
	puts("");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44354699/article/details/88232914