Peap commited on
Commit
c4fc154
·
1 Parent(s): 433f063

Create Code.cpp

Browse files
Files changed (1) hide show
  1. Code.cpp +85 -0
Code.cpp ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <bits/stdc++.h>
2
+ #include <curl/curl.h>
3
+ using namespace std;
4
+
5
+ int main() {
6
+ CURL *curl;
7
+ CURLcode res;
8
+ curl = curl_easy_init();
9
+ if(curl) {
10
+ curl_easy_setopt(curl, CURLOPT_URL, "https://codeforces.com/api/problemset.problems");
11
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
12
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
13
+ res = curl_easy_perform(curl);
14
+ if(res != CURLE_OK) {
15
+ fprintf(stderr, "curl_easy_perform() failed: %s\n",
16
+ curl_easy_strerror(res));
17
+ }
18
+ curl_easy_cleanup(curl);
19
+ }
20
+ }
21
+
22
+ size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
23
+ {
24
+ ((std::string*)userp)->append((char*)contents, size * nmemb);
25
+ return size * nmemb;
26
+ }
27
+
28
+
29
+ class DeepReinforcementLearningAgent {
30
+ public:
31
+ void initialize() {
32
+ // Initialize neural network, Q-table, epsilon, etc.
33
+ }
34
+
35
+ int getAction(std::string problem) {
36
+ // Use neural network and Q-table to determine an action (solution)
37
+ // for the given CodeForces problem.
38
+ return action;
39
+ }
40
+
41
+ void update(double reward, std::string problem, int action) {
42
+ // Update neural network and Q-table using the reward for the previous
43
+ // action on the given problem.
44
+ }
45
+ };
46
+
47
+ int main() {
48
+ DeepReinforcementLearningAgent agent;
49
+ agent.initialize();
50
+
51
+ CURL *curl;
52
+ CURLcode res;
53
+ std::string response;
54
+ curl = curl_easy_init();
55
+
56
+ while (true) {
57
+ curl_easy_setopt(curl, CURLOPT_URL, "https://codeforces.com/api/problemset.problems");
58
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
59
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
60
+ res = curl_easy_perform(curl);
61
+ if(res != CURLE_OK) {
62
+ // Handle error
63
+ }
64
+
65
+ // Get next unsolved problem from response string
66
+ std::string problem = ...
67
+
68
+ int action = agent.getAction(problem);
69
+ std::string solution = getSolution(action); // Submit solution
70
+ // and get result
71
+
72
+ double reward;
73
+ if (result == "Accepted") reward = 1;
74
+ else if (result == "Compilation Error") reward = -0.5;
75
+ else if (result == "Wrong Answer") reward = 0.1;
76
+ else if (result == "Time Limit Exceeded") reward = 0.2;
77
+
78
+ agent.update(reward, problem, action);
79
+
80
+ if (result == "Accepted") std::cout << "Accepted" << '\n';
81
+ else if (result == "Compilation Error") std::cout << "Compilation Error" << '\n';
82
+ else if (result == "Wrong Answer") std::cout << "Wrong Answer" << '\n';
83
+ else std::cout << "Time Limit Exceeded" << '\n';
84
+ }
85
+ }