首页 > 其他分享 >出题代码

出题代码

时间:2024-07-15 17:51:23浏览次数:11  
标签:string int 代码 scta ProblemHelper 出题 time include

#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

相关文章

  • 代码随想录算法训练营第22天 |二叉树part07:235. 二叉搜索树的最近公共祖先、701.二叉
    代码随想录算法训练营第22天|二叉树part07:235.二叉搜索树的最近公共祖先、701.二叉搜索树中的插入操作、450.删除二叉搜索树中的节点235.二叉搜索树的最近公共祖先https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree/description/代码随想录:htt......
  • 微信小程序代码审计小记
    本文参考文章地址:https://zhuanlan.zhihu.com/p/694193212准备工具1.反编译后的小程序文件夹详情请参考《日拱一卒之微信小程序自动化辅助渗透工具》https://www.cnblogs.com/--l-/p/182455582.审阅工具vscode2.1下载VsCode。点击图示位置的“下载”即可。下载地址:htt......
  • Ajax代码运行前应该先加载jQuery
    <scriptsrc="{%static'js/jquery-3.6.0.min.js'%}"></script><script>//使用jQuery获取分类列表并绑定点击事件,用于自动更新【博客分类】阅读$(document).ready(function(){$('#category-list').on('click','li',fun......
  • 为什么执行代码,烧入程序之后,电脑对单片机发送数据,但是单片机不反应
    #include"stm32f10x.h"      #include"Uart.h"#include<stdio.h>#include<stdarg.h>u8USART1_RX_BUF[64];  //接收缓冲,最大64个字节.//接收状态//bit7,接收完成标志//bit6,接收到0x0d//bit5~0,接收到的有效字节数目u16USART1_RX_STA=0;   ......
  • kimi写代码:c++ 线程池
    https://kimi.moonshot.cn/share/cqaberkdvond1bljn8sg在这个示例中:线程池创建了固定数量的工作线程。enqueue方法用于将任务添加到队列,并返回一个std::future对象,可用于获取任务的结果。每个工作线程在循环中等待任务分配,并在接收到任务后执行它。当线程完成分配的任务后......
  • python 20行代码 无图 turtle 缺心眼(缺良心)还没治好 模拟太阳系天体运行系统
    短短12h赞就破10个了,没20个很好了,我可不想失去头发其实我不想做这个程序的但是今天是我参加完天文比赛的10分之57周年(我2024.5.12参加的)20行以下代码段为准本期新规矩:天王18步老规矩.先放代码importturtle,time;screen=turtle.Screen();screen.bgcolor('black');scr......
  • JavaSE项目--图书管理系统代码
    结构代码展示Book类代码packagecom.xszx.beans;//实体类publicclassBook{privateintid;privateStringname;privateintbsum;publicBook(){}publicBook(intid,Stringname,intbsum){this.id=id;......
  • 使用idea从本地上传代码到gitee
    1.登陆Gitee(登录-Gitee.com),没有就注册一个2.点击新建仓库3.填完点击创建4.用idea打开一个项目(或创建一个项目),,,file——open(这个不用教了吧)注意:绝大多数项目都包含后端、前端、甚至app、小程序代码,所以本地代码上传到Gitee时一定要选择包含全部项目的文件夹例如:5.这里......
  • SMOTE与SMOGN算法R语言代码
      本文介绍基于R语言中的UBL包,读取.csv格式的Excel表格文件,实现SMOTE算法与SMOGN算法,对机器学习、深度学习回归中,训练数据集不平衡的情况加以解决的具体方法。  在之前的文章SMOGN算法Python实现:解决回归分析中的数据不平衡中,我们介绍了基于Python语言中的smogn包,实现SMOGN算......
  • 基于智能优化算法实现自动泊车的路径动态规划(Matlab代码实现)
    ......