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