-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guilherme
committed
Sep 18, 2018
1 parent
31ce6d8
commit 55ab6fc
Showing
94 changed files
with
56,328 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.