[Legend] simple math doomsday

[Legend] simple math doomsday

topic

Title Description

As long as students must participate in the activities jsoi heard about the legendary Tower of Hanoi: gold pieces on the three pillars to be moved once a day, after all the gold pieces have been shifted completely, along with it comes the end of the world.

In the ancient oriental fantasy Township, people have adopted a strange way the Record Date: they use some special symbols to represent consecutive integers beginning with 1, N 1 represents the minimum and maximum representation. The first day of Genesis, the calendar was given a life, it automatically starts counting, as arranged constantly increasing.

We used 1-N to represent elements of the calendar, the first day of the calendar is

1, 2, 3, … N

The next day, the calendar automatically changes

1, 2, 3, … N, N-1

...... each time it generates not seen before a "minimal" arrangement - it into N + 1 after the minimum number of decimal numbers.

As the days to live. One day, a prophet appeared - he predicts, when the arrival time of a calendar arranged by God, the world will collapse ...... He also predicted that, if a reverse certain date to reach a value of M when end of the world is coming.

What is the reverse? Calendar in two different symbols, if later than the top surface of the back row in the larger, is a reverse, a reverse date total reached M, the end is coming, people are looking forward to a Sage, able to anticipate that day, in the end will come at what time?

Input Format

Row contains only two positive integers, respectively, N and M.

Output Format

Output line, the date of the end of the world, between each number separated by a space.

Sample input and output

Input # 1 copy
54
output # 1 replication
13542

Description / Tips

For 10% of the data has N <= 10.

For 40% of the data has N <= 1000.

For data with a 100% N <= 50000.

All data are the solution.

analysis

Road before yesterday did the reverse order to see this problem immediately to do, the result is all wrong, the problem is completely different ,,,,,,,,,, uh uh uh
then re-read the question, ah, no. . . . . . . Uncomfortable

Title: Requirements reverse order when reached a value of M when the end of the world is coming. (Shivering).
What is the reverse: that the top surface of the row than in the larger back is a reverse order.

This question requires a look at a number, for example: 1,2,3,4,5 is beginning, (sample)
then when arranged in reverse order up to 5,4,3,2,1, there are (4 + 1) * 4/2, * use the formula (. 1-n-) n-/ 2 (here, it is well understood)

1 ... subject requires a minimum so sort. .
Look at the first number, 1, if a row in the final, so there is a maximum of (4 + 1) * 4/2 in reverse order, this time we put it aside,
look at the second number, 2, (which when several, 2,3,4,5) if the last 2, there are a maximum of (3 + 1) * 3/2 == 6, 6 is larger than
required to reach inverse number m = 4 (sample), such that is the case whether you put 1 before or after, I do not need 1 can be discharged
in reverse sequence number m = 4, then great, we put one on the front, (because the topics you want to sort the smallest). . .
Are the same reasoning behind, to see a number after the current number, if it is greater than the maximum number of reverse m, If so, it is placed in front,

If it is less than 2 ...? If less than, then the number on the final surface, and then see how many reverse order, m lose. (Just look at the number in front of the digits)
(such as 2 on the final surface, then 1 on the front, 2 front than he has 3,4,5, three, then the number of reverse 3,)

3 ... we open array to store front are put in front of the array, put back behind the array, the array output last order just fine.

Is not too long-winded ,,,,,,, not to write clearly (and long-winded, huh .....)

Code

#include<iostream>

using namespace std;

long long  n,m;
int a[50005];
				
int main(){
	cin>>n>>m;
	int s=1,t=n;
	for(int  i=1;i<=n;i++){
		long long maxi = (n-i)*(n-i-1) /2;
		if(maxi >=m){
			a[s] = i;
			s++;
		}else{
			a[t] = i;
			t--;
			 m -= n-i; 
		}
	}
	for(int i=1;i<=n-1;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n]<<endl;
	return 0;
}
Published 75 original articles · won praise 1 · views 3642

Guess you like

Origin blog.csdn.net/A793488316/article/details/104666588