-
Notifications
You must be signed in to change notification settings - Fork 0
/
self_describing_sequence.cpp
50 lines (44 loc) · 1.22 KB
/
self_describing_sequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Made by: Romeu I. L. Pires
for "Special topics in programming" course
in UFRJ (Universidade Federal do Rio de Janeiro),
on 2019.1 semester
- Problem PDF:
https://uva.onlinejudge.org/external/100/p10049.pdf
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int fn( int N , const vector<int>& milestones ){
for( size_t t = 1 ; t < milestones.size() ; t++ ){
if( N < milestones[t] ) return t;
}
int last_milestone = milestones[milestones.size()-1];
if( N < last_milestone + milestones.size() ){
return milestones.size();
}else{
return -1;
}
}
int main(){
#ifndef ONLINE_JUDGE
ifstream cin("entrada.txt");
ofstream cout("saida.txt");
#endif
// ==========
//Pre-bake fn vector
vector<int> milestones(0);
milestones.push_back(1);
int current_i = 1;
int last_milestone = 1;
while( milestones[milestones.size()-1] < 2000000000 ){
milestones.push_back( last_milestone + fn(current_i++,milestones) );
last_milestone = milestones[milestones.size()-1];
}
int x;
while( cin >> x && x > 0)
cout << fn(x,milestones) << endl;
}