UVa 144-student Grants

Source: Internet
Author: User

Title: There are N student platoon to collect money, the money that the teller machine gives each time is a sequential increment sequence, start from 1 start to K and begin from 1;

If the student is able to leave at 40 yuan, or return to the end of the team, if the money is given plus 40 of the money in the student's hands,

The rest of the money to the next person, please input the left sequence number.

Analysis: Digital Structures (DS), simulation. By using the team modeling, note that if the rest of the money is not taken away, no new money will be given.

SAY: It's been a long time without a problem ╮(╯▽╰)╭.

#include <cstring> #include <cstdio>typedef struct _queue{int id;int value;_queue (int I, int V) {id = I; value = V; }_queue () {}}queue;queue Q[1001],temp;int queue_head = 0;int Queue_tail = 0;void queue_initial () {queue_head = 0;queue_ tail = 0;memset (q, 0, sizeof (q));} void Queue_insert (Queue a) {Q[queue_tail + +] = A;} Queue Queue_delete () {return q[queue_head + +];} int main () {int n, k;while (~scanf ("%d%d", &n,&k) && n+k) {queue_initial (); for (int i = 1; I <= n; + + i) q Ueue_insert (Queue (i, 0)); int value = 1,last = 1;while (n) {Temp = Queue_delete (); last = Value;while (n && last+tem P.value >=) {last = last+temp.value-40;printf ("%3d", temp.id); n--;if (last) Temp = Queue_delete ();} if (last) {temp.value + = Last;queue_insert (Temp);} if (+ + value > K) value = 1;} printf ("\ n");}    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVa 144-student Grants

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.