Turn on the light (Language entry)

Source: Internet
Author: User

/*************************************** **************************************** * ******** Question link: http://acm.nyist.net/JudgeOnline/problem.php? Pid = 77 th path: first, input 2 data, then define an array, there are only two States between the lamp, so it is defined as the bool type, and then initialized to 0, indicates that all lights are turned off at first. Then there are two cycles. The External Loop starts from the person numbered 1 until the end. The cycle indicates that the operation is performed from the lamp numbered 1, and the status of the lamp meeting the requirements is changed to the opposite. Finally, determine which lights are on and output their numbers. In the final output, there is no space in front of the first output, and there are spaces in front of other results. Therefore, the first one is considered separately. **************************************** **************************************** * *******/# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; int main (void) {int n, k; while (cin> n> k) {bool * lamp = (bool *) malloc (n + 2) * sizeof (bool); memset (lamp, 0, (n + 2) * sizeof (lamp); for (int I = 1; I <= k; I ++) // Number of people traversing for (int j = 1; j <= n; j ++) // Number of lights traversal if (j % I = 0) * (lamp + j) =! * (Lamp + j); cout <1; for (int j = 2; j <= n; j ++) if (* (lamp + j) = 1) cout <"" <
    
     

Related Article

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.