#include <bits/stdc++.h>
#include <Windows.h>
#include <exception>
#include <chrono>
using namespace std;
#define scta(a) SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), a);
class ProblemHelper {
public:
ProblemHelper() {
string userDesk(getenv("USERPROFILE"));
readPath = writePath = userDesk + "\\Desktop";
width = 3;
}
ProblemHelper(string rp, string wp, string pn, int w) : readPath(rp), writePath(wp), problemName(pn), width(w) {}
string getId(int i) {
stringstream ss;
ss << setw(width) << setfill('0') << i;
string s = ss.str();
return s;
}
void qopen(int i) {
string s = readPath + "\\" + problemName + getId(i) + ".in";
freopen(s.c_str(), "w", stdout);
}
void aopen(int i) {
string id = getId(i);
string rs = readPath + "\\" + problemName + id + ".in";
freopen(rs.c_str(), "r", stdin);
string ws = writePath + "\\" + problemName + id + ".out";
freopen(ws.c_str(), "w", stdout);
start_time_ = chrono::high_resolution_clock::now();
}
void close() {
cin.clear();
cout.clear();
fclose(stdin);
fclose(stdout);
}
void setReadPath(string path) { readPath = path; }
string getReadPath() { return readPath; }
void setWritePath(string path) { }
string getWritePath() { return writePath; }
void setProblemName(string name) { problemName = name; }
string getProblemName() { return problemName; }
void phint(int f) {
if (f > 0) {
scta(12); cerr << "+ Problem #" << f; scta(15); cerr << ": Generating data...";
} else {
Sleep(50); scta(10); cerr << "\t\t\t[OK]\n"; scta(15);
}
}
void ahint(int f) {
if (f > 0) {
scta(12); cerr << "- Answers #" << f; scta(15); cerr << ": Generating data...";
} else {
end_time_ = chrono::high_resolution_clock::now();
chrono::duration<double, std::milli> duration_ms = end_time_ - start_time_;
double ms = duration_ms.count();
Sleep(50); scta(10); cerr << "\t\t\t[OK]"; Sleep(50);
if (ms <= 250) { scta(2); }
else if (ms <= 500) { scta(6); }
else if (ms <= 750) { scta(5); }
else { scta(4); }
cerr << "\t Time used: " << ms << " ms.\n\n\n";
scta(15);
}
}
void rhint(const exception& e) {
scta(14); cerr << "\t\t\t[ERROR]\t" << e.what(); scta(15);
}
private:
string readPath, writePath, problemName;
int width;
chrono::time_point<chrono::high_resolution_clock> start_time_, end_time_;
};
ProblemHelper ph("D:\\Codes", "D:\\Codes", "data", 3);
void TLE_SPFA_RECTANGLE(int length, int width) {
random_device rd;
unsigned seed = rd() ^ (chrono::system_clock::now().time_since_epoch().count() + (rd() << 1));
mt19937 rng(seed);
using RD = uniform_real_distribution<double>;
using RI = uniform_int_distribution<long long>;
struct edge {
int u, v, w;
};
vector<edge> v;
int id[110][110]{}, n = length, tp = 0, m = width, a[100000]{};
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) id[i][j] = ++tp, a[tp] = tp;
RI W(1, 29999);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (i < n) {
v.push_back(edge{id[i][j], id[i + 1][j], 1});
v.push_back(edge{id[i + 1][j], id[i][j], 1});
if (j < m) {
if (1)
v.push_back(edge{id[i][j], id[i + 1][j + 1], (int)W(rng)});
else
v.push_back(edge{id[i + 1][j + 1], id[i][j], (int)W(rng)});
}
}
if (j < m) {
v.push_back(edge{id[i][j], id[i][j + 1], (int)W(rng)});
v.push_back(edge{id[i][j + 1], id[i][j], (int)W(rng)});
}
}
}
fprintf(stderr, "[e=%d,L=%d,W=%d]\n", v.size(), n, m);
shuffle(v.begin(), v.end(), rng);
RI NOS(1, tp);
printf("%d %d %d", tp, v.size(), NOS(rng));
for (int i = 0; i < v.size(); ++i)
printf("\n%d %d %d", a[v[i].u], a[v[i].v], v[i].w);
}
void ques(int ix) {
ph.qopen(ix);
// int l = 100, w = 100;
// TLE_SPFA_RECTANGLE(l, w);
// return ;
// 每次重新设置 seed 放置多次编译运行后相同结果
random_device rd;
unsigned seed = rd() ^ (chrono::system_clock::now().time_since_epoch().count() + (rd() << 1));
mt19937 rng(seed);
using RD = uniform_real_distribution<double>;
using RI = uniform_int_distribution<long long>;
RI X(1, 1000000), NS(4000000000, 1000000000000), S(0, 9);
// 从这里开始编写生成代码
if (ix < 5) cout << X(rng) << " " << S(rng) << "\n";
else cout << NS(rng) << " " << S(rng) << "\n";
}
// 标程全局变量尽量在这以下编写
void answ(int ix) {
ph.aopen(ix);
// 从这里开始编写标程
long long n;
int x;
cin >> n >> x;
int sum = 0;
while (n != 0) {
if (n % 10 == x) sum++;
n /= 10;
}
cout << sum << "\n";
}
int main() {
// 题目测试点数
const int S = 1, E = 10;
for (int i = S; i <= E; i++) {
// 生成数据
ph.phint(i); try { ques(i); } catch (const exception& e) { ph.rhint(e); goto OVERS; } ph.phint(-i);
// 生成答案
ph.ahint(i); try { answ(i); } catch (const exception& e) { ph.rhint(e); goto OVERS; } ph.ahint(-i);
ph.close();
}
OVERS:
return 0;
}
标签:string,int,代码,scta,ProblemHelper,出题,time,include
From: https://www.cnblogs.com/iocc/p/18303675