Poj 1234 ball toss

Source: Internet
Author: User
// Contributed a wa because the following sentence is ignored: "NOTE that classmate number 1 initially has the ball and tosses it to classmate K. // Thus, number 1 has not yet been tossed the ball and so does not switch the direction he is thinking. "It means that although the ball is in classmate 1's/hand, whether the ball has been passed is recorded as false! Please note! Note that "she throws it back into ss the circle one place to the left // (from her perspective) of the person who threw her the ball "should pay attention to the sentence in the brackets. It is important to say: this direction is the left and right directions of a person, // not the left and right directions of a person! # Include <iostream> # include <string> using namespace STD; struct info // {int num for storing the information of students; // char direction for students; // The imaginary direction is bool flag; // whether the ball has been taken, that is, whether a student has passed the ball to his int leftnum; // the number on his left in the eyes of other students! Int rightnum; // the number on the right of another student! Int left; // the number on his left, for itself! Int right; // the number on his right!} Info [35]; int main () {int N, K, I, pre, C, TMP; char temp; bool ff; while (CIN> N & N) {CIN> K; for (I = 1; I <= N; I ++) // input {CIN> temp; Info [I]. num = I; Info [I]. direction = temp; Info [I]. flag = false;} // returns the value of info [1] to the number of left and right sides. rightnum = 2; Info [1]. left = 2; Info [1]. leftnum = N; Info [1]. right = N; Info [N]. rightnum = 1; Info [N]. left = 1; Info [N]. leftnum = n-1; Info [N]. right = n-1; for (I = 2; I <n; I ++) {info [I]. rightnum = I + 1; Info [I]. left = I + 1; Info [I]. leftnum = I-1; Info [I]. right = I-1;} Pre = 1; C = 1; FF = false; while (1) {for (I = 1; I <= N; I ++) {If (! Info [I]. Flag) {FF = true; break ;}// you can use the following conditions to discuss four of them! If (FF) {If (info [K]. direction = 'l') {info [K]. flag = true; If (pre = info [K]. left) {info [K]. direction = 'R'; TMP = info [K]. right;} else {info [K]. direction = 'R'; TMP = info [pre]. leftnum ;}} else if (info [K]. direction = 'R') {info [K]. flag = true; If (pre = info [K]. right) {info [K]. direction = 'l'; TMP = info [K]. left;} else {info [K]. direction = 'l'; TMP = info [pre]. rightnum ;}pre = K; k = TMP; FF = false; C ++;} else break ;} cout <"Classmate" <PRE <"got the ball last after" <C-1 <"tosses. "<Endl;} system (" pause ");}

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.