/
ebbinghaus.cpp
executable file
·102 lines (82 loc) · 2 KB
/
ebbinghaus.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* =====================================================================================
*
* Filename: ebbinghaus.cpp
*
* Description: POJ 3730
*
* Version: 1.0
* Created: 04/23/2009 06:09:03 PM
* Revision: none
* Compiler: gcc
*
* Author: Ming Chen (chm), mingchen@cse.buaa.edu.cn
* Company: BUAA.edu
*
* =====================================================================================
*/
#include <iostream>
#include <vector>
using namespace std;
const int MAX_PERIOD = 1000;
const char MAX_TM = 3;
const char NEW_TM = 2;
const char REVIEW_TM = 1;
const char NEW_FREE = 1;
const char REVIEW_FREE = 2;
int review_num = 0;
int reviews[MAX_PERIOD] = {0};
class Schedule {
public :
int today, period;
std::vector<char> timetable;
Schedule(int p) : today(0), period(p), timetable(p, 0) {
}
void proceed() {
timetable[today] = 0;
++today;
if ( today == period ) today = 0;
}
void study_new() {
timetable[today] += NEW_TM;
for ( int i=0; i<review_num; ++i ) {
int r = today + reviews[i];
if ( r>=period ) r -= period;
timetable[r] += REVIEW_TM;
}
}
bool is_free() {
if ( timetable[today] > NEW_FREE ) return false;
for ( int i=0; i<review_num; ++i ) {
int r = today + reviews[i];
if ( r>=period ) r -= period;
if ( timetable[r] > REVIEW_FREE ) return false;
}
return true;
}
};
int
main ( int argc, char *argv[] )
{
int m, days, studied;
cin >> m >> review_num;
if ( review_num == 0 ) {
cout << m << endl;
return 0;
}
for ( int i=0; i < review_num; ++i ) {
cin >> reviews[i];
--reviews[i];
}
Schedule schedule(reviews[review_num-1]+1);
studied = 0;
for ( days=0; studied < m; ++days ) {
if ( schedule.is_free() ) {
schedule.study_new();
++studied;
}
schedule.proceed();
}
cout << days + schedule.period - 1 << endl;
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */