当前位置:网站首页>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;
}
边栏推荐
- Remove duplicates from an ordered array
- The grass is bearing seeds
- Binary tree -- using hierarchical sequence and middle sequence to determine a tree
- The tle4253gs is a monolithic integrated low dropout tracking regulator in a small pg-dso-8 package.
- Facial expression recognition dataset
- Androi weather
- Illustrator tutorial, how to add dashes and arrows in illustrator?
- Leetcode-11- container with the most water (medium)
- Rotating camera
- HashSet underlying source code
猜你喜欢

深度学习模型剪枝
![[JS component] customize the right-click menu](/img/a3/4555619db17e4c398e72c7d6b12f5d.jpg)
[JS component] customize the right-click menu

Pipeline pipeline project construction

What is dummy change?

How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators

4K sea bottom and water surface fabrication method and ocean bump displacement texture Download

(01). Net Maui actual construction project

Application advantages of 5g industrial gateway in coal industry

How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators

Most elements leetcode
随机推荐
Quick power explanation
[JS component] calendar
MySQL transaction
How to handle different types of data
Andersen global expands its business in northern Europe through cooperation agreements in Finland and Denmark
在国企做软件测试工程师是一种什么样的体验:每天过的像打仗一样
Pytorch's leafnode understanding
生态聚合NFT来袭,Metaverse Ape引领Web 3.0元宇宙新范式革命
5G工业网关在煤矿行业的应用优势
How to solve the problem of database?
leetode. 242. valid Letter heteronyms
About_ int128
[Latex] 插入圖片
[JS component] dazzle radio box and multi box
关于#数据库#的问题,如何解决?
Polymorphism and virtual function
Downloading wiki corpus and aligning with multilingual wikis
With a market value of more than trillion yuan and a sales volume of more than 100000 yuan for three consecutive months, will BYD become the strongest domestic brand?
[JS component] create a custom horizontal and vertical scroll bar following the steam style
Illustrator tutorial, how to add dashes and arrows in illustrator?