-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA 10276 - Hanoi Tower Troubles Again!.cpp
More file actions
95 lines (78 loc) · 2.55 KB
/
UVA 10276 - Hanoi Tower Troubles Again!.cpp
File metadata and controls
95 lines (78 loc) · 2.55 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// std::ios_base::sync_with_stdio(false); // (removes the interoperability that happens between C's stdio.h and iostream )
// std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ); //(will neglect the c's stdio.h property of doing inline flushing with every line of code)
#include <iostream>
#include<numeric>
#include<vector>
#include<cmath>
#include<stack>
#include <iomanip>
#include <vector>
//#include<bits/stdc++.h>
#include <bitset>
//#include<iomanip>
#include <algorithm>
#include<queue>
//#include<deque>
//#include<numeric>
#include<set>
//#include<unordered_set>
#include<map>
//#include<fstream>
//#include<sstream>
//#include <thread>
//#include <chrono>
#include<cstring>
#include<string>
#include <unordered_map>
#include<memory>
#include <iostream>
#include <thread>
/*Warning It's a stupid solution though it works */
int main(){
int testCase;
std::cin>>testCase;
while(testCase--){
int n;
std::cin>>n;
std::pair<int,int> arr[n]{std::make_pair(0,0)}; //first is the upper one,second is the lower one
int current = 0;
while(++current){
bool oldPlaced =0;
for(int i = 0 ;i<n;i++){
if (arr[i].second == 0 && arr[i].first != 0){
double num = std::sqrt(arr[i].first+current);
int num1 = std::sqrt(arr[i].first+current);
if (num == num1){
arr[i].second = arr[i].first;
arr[i].first = current;
oldPlaced = 1;
break;
}
}
else{
int &&num = std::pow(std::sqrt(arr[i].first + arr[i].second)+1,2);
int required = num -arr[i].first;
if (required == current){
arr[i].second = arr[i].first;
arr[i].first = current;
oldPlaced = 1;
break;
}
}
}
bool weDoomed = 1;
if(!oldPlaced){
for(int i = 0 ;i<n;i++){
if (arr[i].first == 0 && arr[i].second == 0){
arr[i].first = current;
weDoomed = 0;
break;
}
}
}
if (weDoomed &&!oldPlaced) break;
}
std::cout<<current-1<<std::endl;
}
return 0;
}