Skip to content

Commit

Permalink
Adhocs: Time Waster (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme committed Sep 18, 2018
1 parent 31ce6d8 commit 55ab6fc
Show file tree
Hide file tree
Showing 94 changed files with 56,328 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
"args": ["<", "input/${fileBasenameNoExtension}", ">", "output/${fileBasenameNoExtension}"],
"args": ["<", "input/1/4/${fileBasenameNoExtension}", ">", "output/1/4/${fileBasenameNoExtension}"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"cstring": "cpp",
"map": "cpp",
"optional": "cpp",
"string_view": "cpp"
"string_view": "cpp",
"iomanip": "cpp",
"list": "cpp",
"climits": "cpp",
"ctime": "cpp"
}
}
98 changes: 98 additions & 0 deletions 1/4/10033.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename}
*
* This is a template file for C++ Solutions of UVA Judge Online problems
**/

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
int k = 0;
int N;
string output = "";
bool begin = true;

output.reserve(500000);
cin >> N;
cin.ignore();
cin.ignore(); // blank line;

while(k++ < N)
{
bool halted = false;
uint reg[10] = { 0 };
uint instr, op1, op2;
uint counter = 0, total = 0;
vector<int> ram(1000, 0);
string memory = "start";

while (!cin.eof())
{
getline(cin, memory);
if (memory == "") break;
ram[total] = stoi(memory);
total++;
}

if (!begin || (begin = false)) output += "\n";

for ( auto mem = ram.begin();
mem != ram.end() && !halted && (mem - ram.begin() <= total);
mem++ )
{
instr = (*mem) / 100;
op1 = ((*mem) / 10 ) % 10;
op2 = (*mem) % 10;
counter++;

switch (instr)
{
case 1: halted = true; break;
case 2:
reg[op1] = op2;
break;
case 3:
reg[op1] = (reg[op1] + op2) % 1000;
break;
case 4:
reg[op1] = (reg[op1] * op2) % 1000;
break;
case 5:
reg[op1] = reg[op2];
break;
case 6:
reg[op1] = (reg[op1] + reg[op2]) % 1000;
break;
case 7:
reg[op1] = (reg[op1] * reg[op2]) % 1000;
break;
case 8:
reg[op1] = ram[reg[op2]];
break;
case 9:
ram[reg[op2]] = reg[op1];
total = max(reg[op2], total);
break;
case 0:
if (reg[op2])
{
mem = ram.begin() + reg[op1] - 1;
total = max(uint(mem - ram.begin()), total);
}
break;
}
}

output += to_string(counter) + "\n";
}

printf("%s", output.c_str());

return(0);
}
94 changes: 94 additions & 0 deletions 1/4/10134.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename}
*
* This is a template file for C++ Solutions of UVA Judge Online problems
**/

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define FISH 0
#define BAIT 1
#define LUNCH 2

size_t simulate(vector<int> &input)
{
size_t counter = 0;
uint last = 0;
uint bait = 0;
uint fishing = 0;

for ( auto it = input.begin(); it != input.end(); it++ ) {
switch(*it)
{
case FISH:
if ((bait / 2) &&
((last >= 6 && fishing >= 2) || !counter))
{
counter++;
last = 0;
fishing = 0;
bait-=2;
} else
{
if (bait / 2) fishing++;
last++;
}
break;
case BAIT:
bait = min(bait + 1, uint(6));
case LUNCH:
last++;
break;
}
}

return counter;
}

int main()
{
int k = 0;
int N;
string output = "";
string line;
bool begin = true;

output.reserve(500000);
cin >> N;
cin.ignore();
cin.ignore(); // blank line

while(k++ < N)
{
vector<int> input;
while (!cin.eof())
{
getline(cin, line);
if (line == "") break;
switch(line[0])
{
case 'l':
input.push_back(LUNCH);
break;
case 'b':
input.push_back(BAIT);
break;
case 'f':
input.push_back(FISH);
break;
}
}

if (!begin || (begin = false)) output += "\n";
output += to_string(simulate(input)) + "\n";
}

printf("%s", output.c_str());

return(0);
}
161 changes: 161 additions & 0 deletions 1/4/10142.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename}
*
* This is a template file for C++ Solutions of UVA Judge Online problems
**/

#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

class Candidate
{
string name;
int votes;
int index;

public:

Candidate(string name, int index)
: name(name), votes(0), index(index) {}
Candidate()
: name(""), votes(0), index(0) {}

void incr()
{
votes++;
}

string getName() const { return name; }
int getVotes() const { return votes; }
int getIndex() const { return index; }
void reset() { votes = 0; }
};

uint hasWinner(vector<Candidate> &candidates,
vector<queue<int>> &voting,
vector<bool> &invalids)
{
vector<Candidate> winners, vcand;
int highest = 0, lowest = 1000;

for ( auto it = candidates.begin(); it != candidates.end(); it++ ) {
it->reset();
}

for ( auto it = voting.begin(); it != voting.end(); it++ ) {
while (invalids[it->front()])
{
it->pop();
}

candidates[it->front()-1].incr();
}

for ( auto it = candidates.begin(); it != candidates.end(); it++ ) {
if (!invalids[it->getIndex()])
{
lowest = min(it->getVotes(), lowest);
highest = max(it->getVotes(), highest);
}
}

if (highest == lowest ||
(uint)highest * 2 > voting.size())
{
return highest;
}

bool reset = false;
for ( auto it = candidates.begin();
it != candidates.end();
it++ ) {
if(it->getVotes() == lowest)
invalids[it->getIndex()] = true;
// if (reset) it = candidates.begin();
// reset = false;

// if (it->second.getVotes() == lowest)
// {
// it++;
// if (it != candidates.begin())
// it--;
// else
// reset = true;
// }
}

return 0;
}

int main()
{
int k = 0;
int N, input, vote;
string output = "";
string line;
bool begin = true;

output.reserve(500000);
cin >> N;
cin.ignore();
cin.ignore(); // blank line

while(k++ < N)
{
uint winners;
vector<Candidate> candidates;
vector<queue<int>> voting;

cin >> input;
cin.ignore();

vector<bool> invalids(input + 1, false);

for(int ii = 0; ii < input; ii++) {
getline(cin, line);
Candidate c(line, ii + 1);
candidates.push_back(c);
}

while (getline(cin, line))
{
if (line == "") break;
stringstream ss(line);

queue<int> q;

while (!ss.eof())
{
ss >> vote;
q.push(vote);
}

voting.push_back(q);
}

do
{
winners = hasWinner(candidates, voting, invalids);
} while (!winners);

if (!begin || (begin = false)) output += "\n";

for ( auto it = candidates.begin(); it != candidates.end(); it++ ) {
if ((uint)it->getVotes() == winners)
{
output += it->getName() + "\n";
}
}

// output += to_string(k) + "\n";
}

printf("%s", output.c_str());

return(0);
}
Loading

0 comments on commit 55ab6fc

Please sign in to comment.