当前位置:网站首页>L1-049 ladder race seat allocation (20 points) (in-depth understanding of for loop + three-dimensional array + error analysis)
L1-049 ladder race seat allocation (20 points) (in-depth understanding of for loop + three-dimensional array + error analysis)
2022-04-22 23:07:00 【.Ashy.】
describe :
There are a large number of players in the ladder race every year , Make sure that all members of the same school are not adjacent , The allocation of seats becomes a more troublesome thing . So we have the following strategies : Suppose that there is N Schools compete , The first i Schools have M[i] team , Every team 10 Contestants . Line up the players of each school , The first i+1 The players of the team are in i After the team . From 1 Schools start , The first of each school 1 Members of the team were seated in sequence , And then there's the number 2 Team members …… And so on . If there is only 1 The school team has not allocated seats yet , They need to arrange their team members to sit in separate seats . This question asks you to write a program , Automatically generate the seat number of the team members for each school , from 1 Numbered starting .
Input :
Enter the number of colleges and universities in a row N ( No more than 100 The positive integer ); The second line gives N No more than one. 10 The positive integer , Among them the first i The number corresponds to the i The number of participating teams in Universities , Numbers are separated by spaces .
Output :
From 1 The number of colleges and universities 1 Team start , Output the seat number of the team member in sequence . Each team has a line , Between seat numbers 1 Space separation , There must be no extra space at the beginning and end of the line . in addition , Press... On the first line of each university “#X” Output the number of the school X, from 1 Start .
The 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
error analysis :
There was no idea at first , It's hard to simulate , Simulated for a long time , There were only 15 branch , Test point 1,2 I can't get by , Analyzed for a long time , Found the reason for being stuck : If there is only one school student left, there is no row ( Let's say we've reached number 80 individual ), Next to this school , If the school in the last row is still it , Then it's from 82 Start arranging , But if the last one is not this school , It's from 81 Start arranging , The back row spacing is 2;
Ideas :
I have done row first and column first questions before , Analyze the problem , It's jumping around between different schools , We might as well The school element is set to for The innermost loop of the loop , Let the cycle jump from school to school , How to solve the interval problem , Here we introduce a sign pre Record the previous school every time , When determining the interval each time, just compare whether this school is the same as the previous school , All elements use one Three dimensional array storage
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll maxx = 1e18;
const int N = 1e6+100;
const int p = 1e4+10;
const double eps = 1e-8;
int a[101][11][11];// The first dimension is school , The second dimension is the team , The third dimension is the team position
int max1,pre=-1,n,cnt;
int num[101];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>num[i];
max1=max(max1,num[i]);
}// Enter and record the maximum number of teams
for(int i=1;i<=max1;i++)// The first layer traverses the... Of each school i A team
{
for(int j=1;j<=10;j++)// The second layer traverses the second layer of each team j A team member
{
for(int k=1;k<=n;k++)// The last layer traverses each school
{
if(num[k]>=i)// Make sure the school has this team
{
if(k==pre) cnt+=2;
else cnt+=1;// Determine the interval
a[k][i][j]=cnt;// Count
pre=k;// Write down this school
}
}
}
}
for(int i=1;i<=n;i++)
{
cout<<"#"<<i<<endl;
for(int j=1;j<=num[i];j++)
{
for(int k=1;k<=10;k++)
{
if(k!=10)
cout<<a[i][j][k]<<" ";
else
cout<<a[i][j][k]<<endl;
}
}
}
}
reflection :
This question is a right for The understanding of circulation , Simulation is not necessary , Through this question, I have a deeper understanding of the sequence of cycles , TIANTI race, come on !!!
版权声明
本文为[.Ashy.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222256302497.html
边栏推荐
- 挖财学堂的证券账户可靠吗?现在开户安全不?用哪个券商比较好?
- Principle of leftmost matching principle
- [swift] code triggers uibutton click event
- SQL语言详解
- Codeforce1669 A和B
- L1-070 吃火锅 (15 分)
- High number | [differential calculus and application of multivariate functions] error prone problems and detailed explanation of Li Lin 880
- Go language learning notes - read lock reentry leads to deadlock
- How to install cadence software
- L1-067 洛希极限 (10 分)
猜你喜欢
【板栗糖GIS】编程的本质—(视频笔记)
![High number | [differential calculus and application of multivariate functions] error prone problems and detailed explanation of Li Lin 880](/img/24/2c2fa861bc0fb3e0a33d13ce01db38.png)
High number | [differential calculus and application of multivariate functions] error prone problems and detailed explanation of Li Lin 880

【Vmware】Vmware ESXI 6.7 安装

如何快速转载CSDN中的博客

Cap theory

最左匹配原则的原理

SystemVerilog 验证-测试平台编写指南学习笔记(3):连接设计和测试平台

CSV column extract column extraction

The article "fluent" is used to select and upload pictures

Even if you study hard for 30 years, you may be far from wealth
随机推荐
Enter a formula in the Visio text box
基于51单片机的自动浇花系统
Codeforces Round #784 (Div. 4)
Vtkvertex vertex
MySQL configuration adjustment: case insensitive
Anti DDoS attack forwarding IP. Is the advanced anti IP of chess and card games easy to use?
[reproduction of thesis code] errors encountered in the translation embeddings for modeling multi relational data
Minio基本使用與原理
RPC详解
Gbase 8A common parallelism parameter adjustment to improve performance
Codeforce1669 A和B
Even if you study hard for 30 years, you may be far from wealth
Importance of safety product design
High number | [differential calculus and application of multivariate functions] error prone problems and detailed explanation of Li Lin 880
登录功能&新增文章功能的测试点提取以及测试用例编写
RPC details
How to open MT5 account and what products can MT5 trade?
When creating a dynamic link library, the header file reports an error. Expected initializer before "function name"“
3. 源码
AcWing 1842. 牛奶桶 遍历所有情况