ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

time limit exceeded
Posted by lhyx1990 26 Jan 2014 16:27

#include <iostream>
using namespace std;

bool isOne(int n);
int main(int argc, const char * argv[])
{

    int n;
    cin >> n;

    int *nums = new int[n];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        nums[i] = k;
    }

    for (int i = 0; i < n; i++) {
        int index = nums[i] - 1;
        if (isOne(index)) cout << 1 << " ";
        else cout << 0 << " ";
    }
    delete [] nums;
}

bool isOne(int n) {
    int indexOf1 = 0;
    for (int i = 0; indexOf1 < n; i++) {
        indexOf1 += i;
        if (indexOf1 == n)
            return true;
    }
    return false;

}

Edited by author 26.01.2014 16:27