diff --git a/atcoder/practice1.cpp b/atcoder/practice1.cpp new file mode 100644 index 0000000..b041707 --- /dev/null +++ b/atcoder/practice1.cpp @@ -0,0 +1,18 @@ +#include +#include + +using namespace std; + + +int main(){ + int a, b, c; + string s; + + cin >> a; + cin >> b >> c; + cin >> s; + + cout << a + b + c << " " << s << endl; + + return 0; +} \ No newline at end of file diff --git a/base.cpp b/base.cpp index 6cce239..66d7065 100644 --- a/base.cpp +++ b/base.cpp @@ -1,16 +1,17 @@ -#include -#include - -using namespace std; - -int main(){ - - cout << "Hello this is Patrick" << endl; - auto start = chrono::high_resolution_clock::now(); - - // Insert code here - - auto duration = chrono::duration_cast(chrono::high_resolution_clock::now() - start); - cout << (float)duration.count()/1000 << endl; - return 0; +#include +#include +#include +#include + +using namespace std; + + + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + return 0; } \ No newline at end of file diff --git a/google/kickstart/2021roundA/a b/google/kickstart/2021roundA/a new file mode 100755 index 0000000..f93b2f8 Binary files /dev/null and b/google/kickstart/2021roundA/a differ diff --git a/google/kickstart/2021roundA/a.cpp b/google/kickstart/2021roundA/a.cpp new file mode 100644 index 0000000..9fbe393 --- /dev/null +++ b/google/kickstart/2021roundA/a.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +using namespace std; + +void run_case(int test_case){ + int n, k; + string s; + + cin >> n >> k; + cin >> s; + + int result = 0; + + auto ti = s.end() - 1; + int l = s.length(); + for(auto it = s.begin(); it != s.begin() + l/2; ++it){ + if((*it) != (*ti)){ + result++; + } + --ti; + } + cout << "Case #" << test_case << ": " << abs(k - result) << endl; +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + run_case(tc); + cout << flush; + } +} \ No newline at end of file diff --git a/google/kickstart/2021roundA/b b/google/kickstart/2021roundA/b new file mode 100755 index 0000000..4efefe6 Binary files /dev/null and b/google/kickstart/2021roundA/b differ diff --git a/google/kickstart/2021roundA/b.cpp b/google/kickstart/2021roundA/b.cpp new file mode 100644 index 0000000..a5d7adf --- /dev/null +++ b/google/kickstart/2021roundA/b.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + + + +void run_case(){ + int r, c; + + cin >> r >> c; + + vector> table; + table.reserve(r); + + for(int ri = 0; ri < r; ++ri){ + for(int ci = 0; ci < c; ++ci){ + int i; + cin >> i; + table[ri].push_back(i); + } + } + + +} + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + cout << "Case #" << tc << ": "; + run_case(); + } +} \ No newline at end of file diff --git a/001/main.py b/projecteuler/001/main.py similarity index 100% rename from 001/main.py rename to projecteuler/001/main.py diff --git a/002/main.py b/projecteuler/002/main.py similarity index 100% rename from 002/main.py rename to projecteuler/002/main.py diff --git a/003/main.py b/projecteuler/003/main.py similarity index 100% rename from 003/main.py rename to projecteuler/003/main.py diff --git a/004/main.py b/projecteuler/004/main.py similarity index 100% rename from 004/main.py rename to projecteuler/004/main.py diff --git a/005/main.py b/projecteuler/005/main.py similarity index 100% rename from 005/main.py rename to projecteuler/005/main.py diff --git a/006/main.py b/projecteuler/006/main.py similarity index 100% rename from 006/main.py rename to projecteuler/006/main.py diff --git a/007/main.py b/projecteuler/007/main.py similarity index 100% rename from 007/main.py rename to projecteuler/007/main.py diff --git a/008/main.py b/projecteuler/008/main.py similarity index 100% rename from 008/main.py rename to projecteuler/008/main.py diff --git a/009/main.py b/projecteuler/009/main.py similarity index 100% rename from 009/main.py rename to projecteuler/009/main.py diff --git a/010/main.py b/projecteuler/010/main.py similarity index 100% rename from 010/main.py rename to projecteuler/010/main.py diff --git a/011/main.py b/projecteuler/011/main.py similarity index 100% rename from 011/main.py rename to projecteuler/011/main.py diff --git a/012/main.py b/projecteuler/012/main.py similarity index 100% rename from 012/main.py rename to projecteuler/012/main.py diff --git a/013/main.py b/projecteuler/013/main.py similarity index 100% rename from 013/main.py rename to projecteuler/013/main.py diff --git a/014/main.py b/projecteuler/014/main.py similarity index 100% rename from 014/main.py rename to projecteuler/014/main.py diff --git a/015/main.py b/projecteuler/015/main.py similarity index 100% rename from 015/main.py rename to projecteuler/015/main.py diff --git a/016/main.py b/projecteuler/016/main.py similarity index 100% rename from 016/main.py rename to projecteuler/016/main.py diff --git a/017/main.py b/projecteuler/017/main.py similarity index 100% rename from 017/main.py rename to projecteuler/017/main.py diff --git a/018/main.py b/projecteuler/018/main.py similarity index 100% rename from 018/main.py rename to projecteuler/018/main.py diff --git a/019/main.py b/projecteuler/019/main.py similarity index 100% rename from 019/main.py rename to projecteuler/019/main.py diff --git a/020/main.py b/projecteuler/020/main.py similarity index 100% rename from 020/main.py rename to projecteuler/020/main.py diff --git a/021/main.py b/projecteuler/021/main.py similarity index 100% rename from 021/main.py rename to projecteuler/021/main.py diff --git a/022/main.py b/projecteuler/022/main.py similarity index 100% rename from 022/main.py rename to projecteuler/022/main.py diff --git a/022/names.txt b/projecteuler/022/names.txt similarity index 100% rename from 022/names.txt rename to projecteuler/022/names.txt diff --git a/023/main.py b/projecteuler/023/main.py similarity index 100% rename from 023/main.py rename to projecteuler/023/main.py diff --git a/024/main.py b/projecteuler/024/main.py similarity index 100% rename from 024/main.py rename to projecteuler/024/main.py diff --git a/025/main.py b/projecteuler/025/main.py similarity index 100% rename from 025/main.py rename to projecteuler/025/main.py diff --git a/026/main.py b/projecteuler/026/main.py similarity index 100% rename from 026/main.py rename to projecteuler/026/main.py diff --git a/027/main.py b/projecteuler/027/main.py similarity index 100% rename from 027/main.py rename to projecteuler/027/main.py diff --git a/028/main.py b/projecteuler/028/main.py similarity index 100% rename from 028/main.py rename to projecteuler/028/main.py diff --git a/029/main.py b/projecteuler/029/main.py similarity index 100% rename from 029/main.py rename to projecteuler/029/main.py diff --git a/030/main.py b/projecteuler/030/main.py similarity index 100% rename from 030/main.py rename to projecteuler/030/main.py diff --git a/031/main.py b/projecteuler/031/main.py similarity index 100% rename from 031/main.py rename to projecteuler/031/main.py diff --git a/032/main.py b/projecteuler/032/main.py similarity index 100% rename from 032/main.py rename to projecteuler/032/main.py diff --git a/033/main.py b/projecteuler/033/main.py similarity index 100% rename from 033/main.py rename to projecteuler/033/main.py diff --git a/034/main.py b/projecteuler/034/main.py similarity index 100% rename from 034/main.py rename to projecteuler/034/main.py diff --git a/035/main.py b/projecteuler/035/main.py similarity index 100% rename from 035/main.py rename to projecteuler/035/main.py diff --git a/036/main.py b/projecteuler/036/main.py similarity index 100% rename from 036/main.py rename to projecteuler/036/main.py diff --git a/037/main.py b/projecteuler/037/main.py similarity index 100% rename from 037/main.py rename to projecteuler/037/main.py diff --git a/038/main.py b/projecteuler/038/main.py similarity index 100% rename from 038/main.py rename to projecteuler/038/main.py diff --git a/039/main.py b/projecteuler/039/main.py similarity index 100% rename from 039/main.py rename to projecteuler/039/main.py diff --git a/040/main.py b/projecteuler/040/main.py similarity index 100% rename from 040/main.py rename to projecteuler/040/main.py diff --git a/041/main.py b/projecteuler/041/main.py similarity index 100% rename from 041/main.py rename to projecteuler/041/main.py diff --git a/042/main.py b/projecteuler/042/main.py similarity index 100% rename from 042/main.py rename to projecteuler/042/main.py diff --git a/043/main.py b/projecteuler/043/main.py similarity index 100% rename from 043/main.py rename to projecteuler/043/main.py diff --git a/044/main.py b/projecteuler/044/main.py similarity index 100% rename from 044/main.py rename to projecteuler/044/main.py diff --git a/045/main.py b/projecteuler/045/main.py similarity index 100% rename from 045/main.py rename to projecteuler/045/main.py diff --git a/046/main.py b/projecteuler/046/main.py similarity index 100% rename from 046/main.py rename to projecteuler/046/main.py diff --git a/047/main.py b/projecteuler/047/main.py similarity index 100% rename from 047/main.py rename to projecteuler/047/main.py diff --git a/048/main.py b/projecteuler/048/main.py similarity index 100% rename from 048/main.py rename to projecteuler/048/main.py diff --git a/049/main.py b/projecteuler/049/main.py similarity index 100% rename from 049/main.py rename to projecteuler/049/main.py diff --git a/050/main.py b/projecteuler/050/main.py similarity index 100% rename from 050/main.py rename to projecteuler/050/main.py diff --git a/051/main.py b/projecteuler/051/main.py similarity index 100% rename from 051/main.py rename to projecteuler/051/main.py diff --git a/052/main.py b/projecteuler/052/main.py similarity index 100% rename from 052/main.py rename to projecteuler/052/main.py diff --git a/053/main.py b/projecteuler/053/main.py similarity index 100% rename from 053/main.py rename to projecteuler/053/main.py diff --git a/054/main.py b/projecteuler/054/main.py similarity index 100% rename from 054/main.py rename to projecteuler/054/main.py diff --git a/054/poker.txt b/projecteuler/054/poker.txt similarity index 100% rename from 054/poker.txt rename to projecteuler/054/poker.txt diff --git a/055/main.py b/projecteuler/055/main.py similarity index 100% rename from 055/main.py rename to projecteuler/055/main.py diff --git a/056/main.py b/projecteuler/056/main.py similarity index 100% rename from 056/main.py rename to projecteuler/056/main.py diff --git a/057/main.py b/projecteuler/057/main.py similarity index 100% rename from 057/main.py rename to projecteuler/057/main.py diff --git a/058/main.py b/projecteuler/058/main.py similarity index 100% rename from 058/main.py rename to projecteuler/058/main.py diff --git a/059/main.cpp b/projecteuler/059/main.cpp similarity index 100% rename from 059/main.cpp rename to projecteuler/059/main.cpp diff --git a/059/main.py b/projecteuler/059/main.py similarity index 100% rename from 059/main.py rename to projecteuler/059/main.py diff --git a/060/main.cpp b/projecteuler/060/main.cpp similarity index 100% rename from 060/main.cpp rename to projecteuler/060/main.cpp diff --git a/061/main.cpp b/projecteuler/061/main.cpp similarity index 54% rename from 061/main.cpp rename to projecteuler/061/main.cpp index ed81495..ecf18f9 100644 --- a/061/main.cpp +++ b/projecteuler/061/main.cpp @@ -20,6 +20,7 @@ Find the sum of the only ordered set of six cyclic 4-digit numbers for which eac #include #include #include +#include using namespace std; @@ -51,62 +52,80 @@ bool validEnd(uint n){ return n % 100 >= 10; } -void fillVector(std::vector & toFill, const uint bitmask, uint (*calc)(uint n)){ +std::set results; +const unsigned int Limit = 10000; +std::vector all(Limit, 0); +uint finalMask = 0b111111000; + +void fillVector(vector & toFill, const uint bitmask, uint (*calc)(uint n)){ uint value = calc(0); for(uint i = 0; value < 10000; ++i){ if(value >= 1000 && validEnd(value)){ - toFill[value] |= bitmask; + toFill[value] |= bitmask & finalMask; } value = calc(i + 1); } } -// Non-recursive version of Heap's algorithm for permutations -// Source: https://en.wikipedia.org/wiki/Heap%27s_algorithm -vector> permutations(uint n, vector & A){ - vector> result; - vector c(n, 0); - - result.push_back(A); - - uint i = 1; - while(i < n){ - if(c[i] < i){ - if(i % 2 == 0){ - swap(A[0], A[i]); - } else{ - swap(A[c[i]], A[i]); - } - result.push_back(A); - c[i] += 1; - i = 1; - } else{ - c[i] = 0; - i++; - } - } - return result; -} - -bool checkCyclicness(const vector & v){ - for(int i = 0; i < 5; ++i){ - uint end = v[i] % 100; - uint start = v[i + 1] / 100; - - if(end != start){ - return false; - } - } - if(v[5] % 100 != v[0] / 100){ - return false; - } - - return true; -} - void search(vector & sequence, uint mask = 0){ - + unsigned int from = 1000; + unsigned int to = 10000; + + if(!sequence.empty()){ + auto lowerTwoDigits = sequence.back() % 100; + from = lowerTwoDigits * 100; + to = from + 100; + } + + for(auto next = from; next < to; ++next){ + auto categories = all[next]; + if(categories == 0){ + continue; + } + + bool isUnique = true; + for(auto x : sequence){ + if(x == next){ + isUnique = false; + break; + } + if(!isUnique){ + continue; + } + for(auto j = 3; j <=8; ++j){ + auto thisCategory = 1 << j; + if((categories && thisCategory) == 0){ + continue; + } + + if((mask & thisCategory) != 0){ + continue; + } + + auto nextMask = mask | thisCategory; + if(nextMask == finalMask){ + auto first = sequence.front(); + + auto lowerTwoDigits = next % 100; + auto upperTwoDigits = first / 100; + + if(lowerTwoDigits == upperTwoDigits){ + auto sum = next; + for(auto x : sequence){ + sum += x; + } + results.insert(sum); + } + } + else{ + sequence.push_back(next); + search(sequence, nextMask); + sequence.pop_back(); + } + } + } + } } int main(){ @@ -114,21 +133,21 @@ int main(){ cout << "Hello this is Patrick" << endl; auto start = chrono::high_resolution_clock::now(); - // creating big vector with the numeric values and their corresponding mask - uint finalMask = 0b111111000; - // Finally learned what exactly it means when 1 << n, which is nice - vector all(10000, 0); fillVector(all, 1 << 3, triangle); fillVector(all, 1 << 4, square); fillVector(all, 1 << 5, pentagonal); fillVector(all, 1 << 6, hexagonal); fillVector(all, 1 << 7, heptagonal); fillVector(all, 1 << 8, octogonal); - + vector sequence; + search(sequence); + + for(auto x : results){ + cout << x << endl; + } - cout << "Cycle not found" << endl; auto duration = chrono::duration_cast(chrono::high_resolution_clock::now() - start); cout << (float)duration.count()/1000 << endl; return 0; diff --git a/063/main.cpp b/projecteuler/063/main.cpp similarity index 100% rename from 063/main.cpp rename to projecteuler/063/main.cpp diff --git a/CMakeLists.txt b/projecteuler/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to projecteuler/CMakeLists.txt diff --git a/LICENSE b/projecteuler/LICENSE similarity index 100% rename from LICENSE rename to projecteuler/LICENSE diff --git a/README.md b/projecteuler/README.md similarity index 100% rename from README.md rename to projecteuler/README.md diff --git a/projecteuler/base.cpp b/projecteuler/base.cpp new file mode 100644 index 0000000..6cce239 --- /dev/null +++ b/projecteuler/base.cpp @@ -0,0 +1,16 @@ +#include +#include + +using namespace std; + +int main(){ + + cout << "Hello this is Patrick" << endl; + auto start = chrono::high_resolution_clock::now(); + + // Insert code here + + auto duration = chrono::duration_cast(chrono::high_resolution_clock::now() - start); + cout << (float)duration.count()/1000 << endl; + return 0; +} \ No newline at end of file diff --git a/base.py b/projecteuler/base.py similarity index 100% rename from base.py rename to projecteuler/base.py diff --git a/txts/cipher.txt b/projecteuler/txts/cipher.txt similarity index 100% rename from txts/cipher.txt rename to projecteuler/txts/cipher.txt