Finished 2 of usaco

This commit is contained in:
2022-04-15 14:12:34 +02:00
parent a191aec9bb
commit 7a325e8818
3 changed files with 128 additions and 4 deletions

25
usaco/ch1/beads.cpp Normal file
View File

@@ -0,0 +1,25 @@
/*
ID: philipp17
PROG: beads
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream fout ("beads.out");
ifstream fin ("beads.in");
int n;
string s;
fin >> n >> s;
return 0;
}

92
usaco/ch1/friday.cpp Normal file
View File

@@ -0,0 +1,92 @@
/*
ID: philipp17
PROG: friday
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
// We start on Monday, and the daylist has to start on Saturday
vector<int> DAY_COUNTER(7, 0);
int CURRENT_DAY = 2;
bool is_leap(int year){
if(year % 400 == 0){
return true;
} else if(year % 100 == 0){
return false;
} else if(year % 4 == 0){
return true;
}
return false;
}
void monthly_routine(int days){
for(int day = 0; day < days; ++day){
if(day == 12){
DAY_COUNTER[CURRENT_DAY] += 1;
// cout << CURRENT_DAY << endl;
}
CURRENT_DAY = (CURRENT_DAY + 1) % 7;
}
}
int main() {
ofstream fout ("friday.out");
ifstream fin ("friday.in");
int n;
fin >> n;
for(int year = 1900; year < 1900 + n; ++year){
// January
monthly_routine(31);
// February
monthly_routine(is_leap(year) ? 29 : 28);
// March
monthly_routine(31);
// April
monthly_routine(30);
// May
monthly_routine(31);
// June
monthly_routine(30);
// July
monthly_routine(31);
// August
monthly_routine(31);
// September
monthly_routine(30);
// October
monthly_routine(31);
// November
monthly_routine(30);
// December
monthly_routine(31);
}
for(size_t i = 0; i < DAY_COUNTER.size(); ++i){
fout << DAY_COUNTER[i];
if(i != DAY_COUNTER.size() - 1) fout << " ";
} fout << endl;
return 0;
}

View File

@@ -24,7 +24,6 @@ int main() {
map<int, string> index_to_name; map<int, string> index_to_name;
vector<int> bank(np, 0); vector<int> bank(np, 0);
vector<int> spendings(np, 0);
for(int i = 0; i < np; ++i){ for(int i = 0; i < np; ++i){
string s; string s;
@@ -40,15 +39,23 @@ int main() {
fin >> name >> money >> ng; fin >> name >> money >> ng;
// cout << name << " " << money << " " << ng << endl;
if(ng == 0){ if(ng == 0){
continue; continue;
} }
vector<string> receivers(ng); vector<string> receivers(ng);
for(int j = 0; j < ng; ++i){ // cout << ng << endl;
for(int j = 0; j < ng; ++j){
fin >> receivers[j]; fin >> receivers[j];
} }
// for(string s: receivers){
// cout << s << " ";
// }
if(money == 0){ if(money == 0){
continue; continue;
} }
@@ -57,13 +64,13 @@ int main() {
for(const string &receiver : receivers){ for(const string &receiver : receivers){
bank[names_to_index[receiver]] += money_per_person; bank[names_to_index[receiver]] += money_per_person;
spendings[names_to_index[receiver]] -= money_per_person;
} }
bank[names_to_index[name]] -= money_per_person * ng;
} }
// Printing the output // Printing the output
for(int i = 0; i < np; ++i){ for(int i = 0; i < np; ++i){
fout << index_to_name[i] << bank[i] - spendings[i] << endl; fout << index_to_name[i] << " " << bank[i] << endl;
} }
return 0; return 0;