CF 246C Beauty Pageant

Source: Internet
Author: User

Question:
N (1 <= n <= 50) beauty, charm values are different.
There are k (k <= n * (n + 1)/2) days of beauty contests. The beauty values sent to the contests every day are different.
How to arrange this k-day.

Question:
The point is that the charm values are inconsistent with k <= n * (n + 1)/2. What is the condition for Mao k?
First, the charm values are different. Therefore, if the beauty charm values are sorted in descending order.
When I am dispatched, follow the above dispatching rules:
A [1], a [2],..., a [I-1], a [I]
A [1], a [2],..., a [I-1], a [I + 1]
A [1], a [2],..., a [I-1], a [I + 2]
...
A [1], a [2],..., a [I-1], a [n]
Because they are different, these charm values are definitely different.
Assume that when I + 1 people are dispatched, the dispatch method is as follows:
A [1], a [2],..., a [I], a [I + 1]
A [1], a [2],..., a [I], a [I + 2]
A [1], a [2],..., a [I], a [I + 3]
...
A [1], a [2],..., a [I], a [n] www.2cto.com
Similar to moderate I people, and because they are different, these charm values differ from those of moderate I people.
From this point, I found that there are n-I + 1 dispatching method and n-(I + 1) + 1 dispatching method for I + 1.
Therefore, sum (1 ~ N) = n * (n + 1)/2, which is the maximum limit of k. Therefore, this dispatching method can meet the requirements of the questions.


Code:
[Cpp]
# Include <stdlib. h>
# Include <string. h>
# Include <stdio. h>
# Include <ctype. h>
# Include <math. h>
# Include <stack>
# Include <queue>
# Include <map>
# Include <set>
# Include <vector>
# Include <string>
# Include <iostream>
# Include <algorithm>
Using namespace std;
 
# Define ll _ int64
# Define ls rt <1
# Define rs ls | 1
# Define lson l, mid, ls
# Define rson mid + 1, r, rs
# Define middle (l + r)> 1
# Define eps (1e-8)
# Define type int
# Define clr_all (x, c) memset (x, c, sizeof (x ))
# Define clr (x, c, n) memset (x, c, sizeof (x [0]) * (n + 1 ))
# Define MOD 1000000007.
# Define inf 0x3f3f3f
# Define pi acos (-1.0)
# Define _ max (x, y) (x)> (y ))? (X) :( y ))
# Define _ min (x, y) (x) <(y ))? (X) :( y ))
# Define _ abs (x) <0? (-(X) :( x ))
# Define getmin (x, y) (x = (x <0 | (y) <x )? (Y): x)
# Define getmax (x, y) (x = (y)> x )? (Y): x)
Template <class T> void _ swap (T & x, T & y) {T t = x; x = y; y = t ;}
Int TS, cas = 1;
Const int M = 50 + 5;
Int n, kk, a [M];
 
Void run (){
Int I, j, k;
For (I = 1; I <= n; I ++)
Scanf ("% d", & a [I]);
Sort (a + 1, a + n + 1 );
For (I = 1; I <= n & kk; I ++ ){
For (j = 1; j <= n-I + 1 & kk; j ++ ){
Printf ("% d", I );
For (k = n; k> n-I + 1; k --)
Printf ("% d", a [k]);
Printf ("% d \ n", a [j]);
Kk --;
}
}
}
 
Void preSof (){
}
 
Int main (){
// Freopen ("input.txt", "r", stdin );
// Freopen ("output.txt", "w", stdout );
PreSof ();
// Run ();
While (~ Scanf ("% d", & n, & kk) run ();
// For (scanf ("% d", & TS); cas <= TS; cas ++) run ();
Return 0;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.