top of page

CCC 2013 J5/S3

#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; char itlist[3] = {'W','L','T'}; int num_of_games_left = 0; int result; int fave_team; void checking(vector<int> team_to_score){ int f_score = team_to_score[fave_team]; bool flag = false; for(int i = 1; i < 5; i++){ if(i != fave_team && f_score <= team_to_score[i]){ flag = true; break; } } if(flag == false){ result++; } } void play(int gameindex, vector<pair<int,int>> games_left, vector<int> team_to_score){ if (gameindex == num_of_games_left){ //check, update result; checking(team_to_score); return; } //copy the map for(int i = 0; i < 3; i++){ int t1 = games_left[gameindex].first; int t2 = games_left[gameindex].second; if(itlist[i] == 'W'){ team_to_score[t1] += 3; play(gameindex+1, games_left, team_to_score); team_to_score[t1] -= 3; } else if(itlist[i] == 'L'){ team_to_score[t2] += 3; play(gameindex+1, games_left, team_to_score); team_to_score[t2] -= 3; } else{ team_to_score[t1] += 1; team_to_score[t2] += 1; play(gameindex+1, games_left, team_to_score); team_to_score[t1] -= 1; team_to_score[t2] -= 1; } //copy back team_to_score } } int main(){ vector<int> team_to_score(5, 0); cin >> fave_team; int num_of_games_played; cin >> num_of_games_played; vector<pair<int,int>> games_left; games_left.push_back(make_pair(1,2)); games_left.push_back(make_pair(1,3)); games_left.push_back(make_pair(1,4)); games_left.push_back(make_pair(2,3)); games_left.push_back(make_pair(2,4)); games_left.push_back(make_pair(3,4)); for (int x=0; x<num_of_games_played; x++){ int team1; cin >> team1; int team2; cin >> team2; int score1; cin >> score1; int score2; cin >> score2; if (score1 > score2){ team_to_score[team1] += 3; } else if (score1 < score2){ team_to_score[team2] += 3; } else{ team_to_score[team1] += 1; team_to_score[team2] += 1; } for(int i = 0; i < games_left.size(); i++){ if (make_pair(team1,team2) == games_left[i]){ games_left.erase(games_left.begin()+i); } } } num_of_games_left = 6-num_of_games_played; play(0, games_left, team_to_score); cout<<result<<endl;; return 0; }

Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c, sr, sc; cin >> r; cin >> c; int p[r][c]; bool v

CCC '24 J4 - Troublesome Keys

#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { string ps; string ds; cin >> ps; cin >> ds;

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int, int> b){ return a.first < b.first; } bool colcom(pair<int,

Comments


bottom of page