Rebased projecteuler folder, now includes all contest programming stuff
This commit is contained in:
18
atcoder/practice1.cpp
Normal file
18
atcoder/practice1.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
17
base.cpp
17
base.cpp
@@ -1,16 +1,17 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
cout << "Hello this is Patrick" << endl;
|
||||
auto start = chrono::high_resolution_clock::now();
|
||||
|
||||
// Insert code here
|
||||
|
||||
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
|
||||
cout << (float)duration.count()/1000 << endl;
|
||||
return 0;
|
||||
}
|
||||
BIN
google/kickstart/2021roundA/a
Executable file
BIN
google/kickstart/2021roundA/a
Executable file
Binary file not shown.
40
google/kickstart/2021roundA/a.cpp
Normal file
40
google/kickstart/2021roundA/a.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
BIN
google/kickstart/2021roundA/b
Executable file
BIN
google/kickstart/2021roundA/b
Executable file
Binary file not shown.
42
google/kickstart/2021roundA/b.cpp
Normal file
42
google/kickstart/2021roundA/b.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
void run_case(){
|
||||
int r, c;
|
||||
|
||||
cin >> r >> c;
|
||||
|
||||
vector<vector<int>> 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();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ Find the sum of the only ordered set of six cyclic 4-digit numbers for which eac
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -51,62 +52,80 @@ bool validEnd(uint n){
|
||||
return n % 100 >= 10;
|
||||
}
|
||||
|
||||
void fillVector(std::vector<uint> & toFill, const uint bitmask, uint (*calc)(uint n)){
|
||||
std::set<unsigned int> results;
|
||||
const unsigned int Limit = 10000;
|
||||
std::vector<unsigned int> all(Limit, 0);
|
||||
uint finalMask = 0b111111000;
|
||||
|
||||
void fillVector(vector<uint> & 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<vector<uint>> permutations(uint n, vector<uint> & A){
|
||||
vector<vector<uint>> result;
|
||||
vector<uint> 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<uint> & 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<uint> & 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,11 +133,7 @@ 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<uint> all(10000, 0);
|
||||
fillVector(all, 1 << 3, triangle);
|
||||
fillVector(all, 1 << 4, square);
|
||||
fillVector(all, 1 << 5, pentagonal);
|
||||
@@ -126,9 +141,13 @@ int main(){
|
||||
fillVector(all, 1 << 7, heptagonal);
|
||||
fillVector(all, 1 << 8, octogonal);
|
||||
|
||||
vector<uint> sequence;
|
||||
search(sequence);
|
||||
|
||||
for(auto x : results){
|
||||
cout << x << endl;
|
||||
}
|
||||
|
||||
cout << "Cycle not found" << endl;
|
||||
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
|
||||
cout << (float)duration.count()/1000 << endl;
|
||||
return 0;
|
||||
16
projecteuler/base.cpp
Normal file
16
projecteuler/base.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
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::milliseconds>(chrono::high_resolution_clock::now() - start);
|
||||
cout << (float)duration.count()/1000 << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user