UVa 402 m*a*s*h (stl&list)

Source: Internet
Author: User
Tags cas integer time limit

402-m*a*s*h

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=343

Corporal Klinger is a, the 4077th Mobile Army Surgical Hospital in the Korean War; And he'll do just about anything to get out. The U.S. Army has made an offer for a lottery that would choose some number of lucky people (X) to return to the states for A recruiting tour. Klinger needs your help getting out.

The lottery is run by lining the "members of the" at attention and eliminating members by counting off the Me Mbers from 1 ToN where N was a number chosen by pulling cards to the top of a deck. Every Timen is reached, who falls out of the line, and counting begins again at 1 with the "next person" in line. When the "end" of the line has been reached (with whatever number is), the next card in the top of the deck would be Taken, and counting starts again at 1 with the "the" in the "the" remaining line. The last X-people in line get to go home.

Klinger has found a way to trade a stacked deck and the real deck just the before process selection. However, he won't know how many people'll show up for the selection until the last minute. Your job is to write a program that would use the deck Klinger supplies and the number of people in line that he counts jus T before the selection process begins and tell him what position (s) in the "to get" to assure himself of a trip home .

A Simple example with people, 2 lucky spots, and the numbers from cards 3, 5, 4, 3, 2 would show that Klinger should ge T in positions 1 or 8 to go home.

Input

For each selection, you are given a line of integers. The "Tex2html_wrap_inline37" tells how many people'll participate in the lottery. The second integer (tex2html_wrap_inline39) is how many lucky "home" positions would be selected. The next integers are the values of the the ' the ' the ' the ' the ' the ' the ' cards in the deck. Card values are interpretted to integer values between 1 and one inclusive.

Output

For each input line, your are to print the "Selection #A" on A line by itself Wherea is the number of the Selectio n starting with 1 in the top of the input file. The next line would contain a list of ' lucky ' positions that Klinger should attempt to get into. If Klinger ' s deck doesn ' t get the job has been used, print all remaining people in line. The list of ' lucky ' positions is then followed by a blank line.

Sample Input

10 2 3 5 4 3 2 9 6 10 10 6 2 6 7 3 4 7 4 5 3-2
47 6 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5-3

Sample Output

Selection #1
1 8

Selection #2
1 3 16 23 31 47

Directly using list simulation.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Complete code:

/*0.156s*/#include <cstdio> #include <list> using namespace std;  
      
#define SF scanf #define PF printf const int MAXN = 20;  
int CARD[MAXN], x;  
List<int> Li;  
      
List<int>::iterator ITER;  
    void Solve () {int i, J;  
            for (i = 0; i < MAXN. ++i) {for (iter = Li.begin (), j = 1; Iter!= li.end (); ++j) {  
                if (j = = Card[i]) {if (li.size () = = x) return;  
                iter = Li.erase (ITER);  
                After erase, the iterator that points to the deleted node fails///erase (iterator position) returns an iterator that points to the next location of the deleted node (if the last node is deleted, the end iterator is returned)  
            j = 0;  
        else ++iter;  
    int main () {int n, I, cas = 0;  
        while (~SF ("%d%d", &n, &x)) {li.clear ();  
        for (i = 1; I <= n; ++i) li.push_back (i);  
    for (i = 0; i < MAXN ++i) SF ("%d", &card[i]);    Solve ();  
        PF ("Selection #%d\n", ++cas);  
        for (iter = Li.begin (), i = 0; i < li.size ()-1; ++i) pf ("%d", *iter++);  
    PF ("%d\n\n", *iter);  
return 0; }

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.