Turn on the lights (Algorithmic Race Primer Classic)

Source: Internet
Author: User

#include <stdio.h>
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <iomanip>
#include <string.h>
#define MAXN 1005
Using Std::cin;
Using Std::cout;
int a[maxn];//array a[] is defined to be placed in the global position, and then in the main function of the assignment operation, otherwise it will be an error
int main () {
memset (A, 0, sizeof (a));
int N, k, first = 1;
cout << "Please enter numbers:" << Std::endl;
Cin >> k >> N;
if (k <= n && n << 1000) {
for (int i = 1; I <= K; i++) {//per person operation once, so outer loop is human
for (int j = 1; J <= N; j + +) {//each lamp is to be operated by each person once, so the inner loop is human
if (j%i = = 0)
A[J] =!a[j];//very interesting place
for (int m = 0; M <= N; m++) {
if (A[m]) {
If first is 0;//here to avoid unnecessary output of the initial element
else cout << m << Std::endl;
}
}
}
}
}
Else
cout << "Wrong number" << Std::endl;
}

Turn on the lights (Algorithmic Race Primer Classic)

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.