出题代码

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
#define scta(a) SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), a);

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>;

void mode() {
	cout << "\t\t\t\t\t          走迷宫游戏\n";
	cout << "\t\t\t\t\t    请按数字键选择游戏模式\n";
	cout << "\t\t\t\t\t    1.------普通模式------\n";
	cout << "\t\t\t\t\t    2.------记忆模式------\n";
} 

int main() {
	srand(time(0));
	vector<string> maze(48, string(115, '#'));
	
	
	HANDLE hide;	
	CONSOLE_CURSOR_INFO cci;
	hide = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取光标 
	cci.dwSize = 1;							// dwSize 大小 
	cci.bVisible = 0;						// visible 不可见 0 
	SetConsoleCursorInfo(hide, &cci);
	getch();		// 吃任何一个按下的键
	
	int x, y, ex, ey;	// x 行 y 列 是玩家所在的位置, ex 行 ey 列是终点
	for (int i = 0; i < maze.size(); i++) {
		for (int j = 0; j < maze[i].size(); j++) {
			if (maze[i][j] == 'O') x = i, y = j;		// 玩家所在的位置 x  行 y  列
			if (maze[i][j] == '=') ex = i, ey = j;		// 出口所在id位置 ex 行 ey 列 
		}
	} 

	system("cls"); 
	// 玩家还没有走到终点 游戏继续 
	while (x != ex || y != ey) {
		scta(rand() % 15 + 1);
		HANDLE fresh;
		COORD pos{0, 0};
		fresh = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorPosition(fresh, pos);
		
		
		// 显示迷宫
		for (int i = 0; i < maze.size(); i++) {
			cout << maze[i] << "\n";		// 输出每行的迷宫 
		}
		
		// 获取移动方向
		char c = getch();					// 按下 w 上, a 左,s 下, d 右 
		int nx, ny;							// 移动的下一个位置在哪里 
		if (c == 'w' || c == 72) {			// 移动上方
			nx = x - 1;	ny = y; 
		} else if (c == 's' || c == 80) {	// 移动下方 
			nx = x + 1;	ny = y;
		} else if (c == 37 || c == 75) {	// 移动左方 
			nx = x; ny = y - 1;
		} else if (c == 'd' || c == 77) {	// 移动右方 
			nx = x; ny = y + 1;
		}
		
		// 判断新的位置是否是墙壁
		if (nx < 0 || ny < 0 || nx >= maze.size() || ny >= maze[0].size() || maze[nx][ny] == '#') continue;		// 不让它移动
		if (maze[nx][ny] == '=') maze[nx][ny] = ' ';	// 先把终点换成空格 
		swap(maze[x][y], maze[nx][ny]);					// 交换位置 表示移动
		x = nx, y = ny;									// 新的位置 
	}

	system("cls");
	cout << "恭喜逃出迷宫";
	
	return 0;
}
#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;
}
posted @ 2024-07-15 17:54  guanglong  阅读(32)  评论(0)    收藏  举报