Huawei recruitment server trial: 15: Joseph ring, Huawei Joseph

Source: Internet
Author: User

Huawei recruitment server trial: 15: Joseph ring, Huawei Joseph
Huawei recruitment machine trial finishing 15: Joseph Ring

Question: Joseph Ring
Joseph's ring is an application of mathematics: n people (represented by numbers 1, 2, 3... n) are known to be sitting around a round table. The number of people numbered k starts to report, and the person counting m is listed; the next person reporting the number from 1, and the person counting m is listed again; repeat this rule, until all the people around the Round Table are listed.
Question Analysis:
This question is mainly intended to evaluate the knowledge of linked lists.
Algorithm IDEA 1: Use a circular linked list to simulate a circle
Here we use std: list in the template library to simulate a ring linked list. Since std: list is not a ring structure, every time the iterator scans the end of the chain list, remember to move the iterator to the head of the linked list, which is equivalent to traversing in a circle in order.
Algorithm train of thought 2: Use the observation mathematical law to analyze the law of the remaining number, which is also cyclical or recursive.

========================================================== ======================================
Reference code:

// Joseph ring. cpp // 2014.7.11 hepanhui # include <iostream> # include <list> using namespace std;/* algorithm IDEA 1: int Joseph (unsigned int n, unsigned int m) {if (n <1 | m <1) return-1; unsigned int I = 0; list <int> numbers; // initialize the linked list for (I = 0; I <n; I ++) numbers. push_back (I); list <int >:: iterator current = numbers. begin (); while (numbers. size ()> 1) {for (I = 1; I <m; ++ I) {current ++; if (current = numbers. end () current = numbers. begin () ;}list <int >:: iterator next =++ current; if (next = numbers. end () next = numbers. begin (); current --; cout <* (current) <endl; numbers. erase (current); current = next;} return * (current);} */int Joseph (unsigned int n, unsigned int m) {if (n <1 | m <1) return-1; int last = 0; for (int I = 2; I <= n; I ++) last = (last + m) % I; return last;} int main () {unsigned int n, m; cin> n> m; cout <Joseph (n, m) <endl; return 0 ;}

Errors that are easy to make during debugging:
The Code of IDEA 1 has some problems, and the error "list iterator not incrementable" is prompted. Error found. current = numbers. begin (); written by mistake =.


Huawei 2013 campus recruitment, machine trial is complete, when the interview, is it brushed?

We recommend that you go to the corresponding street network and check the fresh graduates network. They have detailed processes.
In addition, you can also go to Sina Weibo directly to @ corresponding recruiters, which include Weibo recruitment for each region of Huawei.
Good luck.

Yesterday, Huawei recruited an opportunity for testing on campus. People familiar with this knowledge knew that it was not easy to do the right thing. Yesterday, they asked the staff that they were doing the right thing.

Don't worry, because there are too many people, you have to give them time, right? Huawei's interview is still fair and fair, and there are basically no backdoors for finding relationships, now that you have a good first test score, you should have a chance to review it. However, there may also be mistakes made by others, so you can find a way to contact the school employment guidance center for HR in two days. I believe it will work and I want to enter Huawei
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.