PTA_L1-049 ladder match seat assignment (20 points)

L1-049 ladder match seat assignment

Ladder tournament every year a large number of team members, to ensure that all members of the same school are not adjacent, assigned seating has become a troublesome thing. To this end we have developed the following strategy: Suppose a stadium participating schools have N, i-schools have M [i] teams, 10 players per team. So that every school player in a single file, i + 1-team players behind the i-team players. From the first a school, the school No. 1 player in turn seated, then the school's first two players ...... and so on. If last only a school's team has not been assigned a seat, you will need to arrange their players compartments sit. This question requires you to write a program to automatically generate a seat number for the school team, numbering from 1.

Input format:
input participating in the given row number of Universities N (positive integer not exceeding 100); a second row of N gives a positive integer not exceeding 10, wherein the i corresponding to the i-th universities teams number, separated by a space between numbers.
Output formats:
from a university of the first teams to start sequentially outputting players seat number. Each team per line, between the seat number separated by a space, the line from beginning to end may not have the extra space. In addition, the first line of each universities by "#X" output number of school X, starting at 1.

Sample input:

3
3 4 2

Sample output:

#1
1 4 7 10 13 16 19 22 25 28
31 34 37 40 43 46 49 52 55 58
61 63 65 67 69 71 73 75 77 79
#2
2 5 8 11 14 17 20 23 26 29
32 35 38 41 44 47 50 53 56 59
62 64 66 68 70 72 74 76 78 80
82 84 86 88 90 92 94 96 98 100
#3
3 6 9 12 15 18 21 24 27 30
33 36 39 42 45 48 51 54 57 60

Ideas: the use of STL containers (vector) of the (deposit different elements).
Complete code:

#include<bits/stdc++.h>
using namespace std;
int a[105];
bool flag[105];
vector <int> Vec[105];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ans=1;
    int num=1;
    while(num-1!=n)
    {
        for(int i=0;i<n;i++)
        {
            if(flag[i])
            {
                continue;
            }
            Vec[i].push_back(ans);
            if(num==n)
            {
                ans+=2;
            }
            else
            {
                ans++;
            }
            int x=Vec[i].size();
            if(x==a[i]*10)
            {
                num++;
                flag[i]=1;
            }
        }
    }
    int bet=0;
    for(int i=0;i<n;i++)
    {
        cout<<"#"<<i+1<<endl;
        int x=Vec[i].size();
        for(int j=0;j<x;j++)
        {
            bet++;
            if(bet==10)
            {
                cout<<Vec[i][j]<<endl;
                bet=0;
            }
            else
            {
                cout<<Vec[i][j]<<" ";
            }
        }
    }
    return 0;
}

Link to the original question:
https://pintia.cn/problem-sets/994805046380707840/problems/994805081289900032

Published 87 original articles · 98 won praise · views 4945

Guess you like

Origin blog.csdn.net/qq_45856289/article/details/104885834