-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgolf_gophers.cpp
More file actions
75 lines (64 loc) · 1.91 KB
/
golf_gophers.cpp
File metadata and controls
75 lines (64 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Made by: Romeu I. L. Pires
for "Special topics in programming" course
in UFRJ (Universidade Federal do Rio de Janeiro),
on 2019.1 semester
- Problem URL (Google Code Jam 2019):
https://codingcompetitions.withgoogle.com/codejam/round/0000000000051635/0000000000104f1a
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
int v[] = { 17,16,13,11,9,7,5 };
pair<int,int> find_new_mod( pair<int,int> mod_A , pair<int,int> mod_B ){
int k = 0;
while( true ){
if( (mod_A.second*k+mod_A.first)%mod_B.second == mod_B.first )
return pair<int,int>( mod_A.second*k+mod_A.first , mod_A.second*mod_B.second );
else
k++;
}
return pair<int,int>(-1,-1);
}
int guess_number( vector< pair<int,int> >& modules ){
pair<int,int> a,b;
while( modules.size() > 1){
a = modules.back();
modules.pop_back();
b = modules.back();
modules.pop_back();
modules.push_back( find_new_mod( a , b) );
}
return modules[0].first;
}
int main(){
int T,N,M,result;
cin >> T >> N >> M;
while( T-- ){
int night_number = 0;
vector< pair<int,int> > modules(7);
while( night_number < 7 ){
int gopher_sum = 0;
int n;
for( int i = 0 ; i < 18 ; i++ )
cout << v[night_number] << ( (i<17) ? ' ' : '\n' );
for( int i = 0 ; i < 18 ; i++ ){
cin >> n;
gopher_sum += n;
}
gopher_sum = gopher_sum % v[night_number];
modules[night_number] = pair<int,int>(gopher_sum,v[night_number]);
night_number++;
}
cout << guess_number( modules ) << endl;
cin >> result;
if( result == -1 ){
cout << "Wrong answer :( " << endl;
}
}
}