mo3az014
BAN USER// Assume we store the binary tree in 1D array
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[7] = { 3, 4, 5, 6, 7, 8, 9 };
int targ = 359, sz = 7;
queue<pair<int, int> > q;
q.push(make_pair(0, targ));
while (!q.empty()) {
int curIdx = q.front().first;
int curVal = arr[q.front().first];
int curTarg = q.front().second;
// cout << curTarg << " " << curIdx << " " << curVal << endl;
q.pop();
stringstream ss;
ss << curTarg;
stringstream ss2;
ss2 << curVal;
string remTargStr = ss.str();
if (ss.str().find(ss2.str()) == 0) {
remTargStr = ss.str().substr(ss2.str().length());
if (remTargStr.length() == 0) {
cout << "YES" << endl;
return 0;
}
} else if (curTarg < targ)
continue;
stringstream ss3;
ss3 << remTargStr;
int remTarg;
ss3 >> remTarg;
if (curIdx * 2 + 1 < sz) {
q.push(make_pair(curIdx * 2 + 1, remTarg));
if (curIdx * 2 + 2 < sz)
q.push(make_pair(curIdx * 2 + 2, remTarg));
}
}
cout << "NO" << endl;
return 0;
}
#include <iostream>
- mo3az014 December 13, 2016#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector <int> numbers(1e6);
vector <int> number_indces(1e6);
int divisor [] = {2,3,4};
// you can sort the divisor and eliminate the multiplier of small divisors
vector <int> div (divisor,divisor+3);
for(int i = 0 ; i < 1e6;i++){
numbers[i] = i;
number_indces[i] = i;
}
cin >> n;
bool die = false;
int divIdx = -1;
for(int i = 0 ; i < div.size();i++){
if(n%div[i] == 0){
die = true;
divIdx = i;
break;
}
}
if(!die){
cout <<"it will survive" <<endl;
}else{
for(int i = 0 ; i <= divIdx;i++){
int idx = 0;
for(int j = 0 ; j < numbers.size();j++){
if(i == divIdx && numbers[j] == n){
cout << "The number will die in index = "<<number_indces[j] << endl;
break;
}
if(number_indces[j] != -1){
if(numbers[j]%div[i] == 0){
number_indces[j] = -1;
}else{
number_indces[j] = idx++;
}
}
}
}
}
return 0;
}