当前位置:网站首页>Vector|hdu-4841 round table questions
Vector|hdu-4841 round table questions
2022-06-13 01:09:00 【includeSteven】
List of articles
HDU 4841 Round table questions
Topic link :HDU 4841 Round table questions
The question
Around the round table 2n personal . among n Individuals are good people , in addition n Individuals are bad people . If you start counting from the first person , Count to m personal , The person shall be executed immediately ; Then start counting after the people who are executed , Count to the third m Personal execution …… In this way, people sitting around the round table are executed . How to arrange the seats of these good and bad people in advance , It can make people put to death n After the individual , The rest of the round table n Individuals are all good people .
Input
Multiple sets of data , Data input for each group : The number of good and bad people n(<=32767)、 step m(<=32767)
Output
For each set of data , Output 2n Capital letters ,‘G’ Show good people ,‘B’ It means bad people ,50 One letter in a line , White space characters are not allowed . There is a blank line between adjacent data .
Sample Input
2 3
2 4
Sample Output
GBBG
BGGB
Ideas :
Use vector simulation , The number is 0-2n-1, All are good people at first , Then count and delete the m personal , Until deleted n One person only ;
Because it's a ring , Every time I count to the m You can delete it personally , So judge the second m The individual needs to take the mold ;
Last vector The rest of us are good people , Then we use the double pointer method , Output the value according to the corresponding position
Be careful :
Attention should be paid to when outputting , There is a blank line between every two sets of data , At the same time, one line can store at most 50 Letters
AC Code : Use G++ Submit
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m){
vector<int> v;
int pos=0; // The location of the person to delete
for(int i=0;i<2*n;i++) v.push_back(i); // The number is 0-2*n-1
for(int i=0;i<n;i++){
pos = (pos+m-1)%(v.size()); // Note that there v The size of is constantly changing , Because they are constantly deleting v The elements in
v.erase(v.begin()+pos);
}
// Double pointer ,j from 0-2*n-1 Traverse , Only when v[i] The number of is equal to j The description number is j Of has not been deleted , That is, the corresponding person is a good person
for(int i=0,j=0;j<2*n;j++){
if(j%50==0 && j) cout<<endl; // When a line is larger than 50 Line break , Be careful j==0 You can't wrap lines
if(i<v.size() && v[i]==j){
i++;
cout<<"G";
}else cout<<"B";
}
cout<<endl<<endl; // Note that there is a blank line between the two rows of data , So you need to output two blank lines
}
return 0;
}
边栏推荐
- Opencv desaturation
- Method of cleaning C disk
- 软件测试的几种分类,一看就明了
- 3623. Merge two ordered arrays
- Leetcode-15- sum of three numbers (medium)
- Install pycharm process
- The tle4253gs is a monolithic integrated low dropout tracking regulator in a small pg-dso-8 package.
- 4K sea bottom and water surface fabrication method and ocean bump displacement texture Download
- Rasa对话机器人之HelpDesk (三)
- Kotlin collaboration, the life cycle of a job
猜你喜欢
Method of cleaning C disk
Four startup modes of kotlin collaboration
Quantitative investment traditional index investment decision vs Monte Carlo simulation method
How many steps are appropriate for each cycle of deep learning?
What kind of experience is it to be a software test engineer in a state-owned enterprise: every day is like a war
spiral matrix visit Search a 2D Matrix
4K sea bottom and water surface fabrication method and ocean bump displacement texture Download
[JS component] calendar
What is the difference between pytorch and tensorflow?
What is dummy change?
随机推荐
Stmarl: a spatio temporal multi agentreinforcement learning approach for cooperative traffic
Understanding of the detach() function of pytorch
Androi weather
Four startup modes of kotlin collaboration
Pysmb usage
深度学习模型剪枝
FLIP动画实现思路
Et5.0 simply transform referencecollectorieditor
Traditional machine learning classification model predicts the rise and fall of stock prices under more than 40 indicators
Leetcode-18- sum of four numbers (medium)
Leetcode-9-palindromes (simple)
Common skills for quantitative investment - drawing 2: drawing the moving average
(01). Net Maui actual construction project
刘徽与《九章算术》《海岛算经》简介
MySQL transaction
[JS component] simulation framework
Leetcode-17- letter combination of phone number (medium)
[JS component] calendar
Minimum spanning tree problem
Rasa对话机器人之HelpDesk (三)