我回来辣
公示栏
下文中蓝色文字均为链接。
头像最后更新于2026.8.24 17:02,以后可能更新较慢。毕竟已经被老师紫菜一次了嘛
域是个好东西。
史上最抽象错误(没有之一):
camelot.cpp:1:23: fatal error: bits/stdc+.h: No such file or directory
#include
^
compilation terminated.人话:bits/stdc++.h 写成 bits/stdc+.h 了。
请注意:下面这张图片,你不破网看不到,破网了照样也看不到。
一个小知识。
如何展示别人主页的链接?非常简单。写个 [链接描述](链接地址) 就行了。但是你如果不喜欢链接的蓝色呢?也很简单,只需要输入这行代码:
[](/user/xxxx)哦,对了,记得把里面的 xxxx 换成用户 id(比如我的个人主页链接是 http://223.99.166.91:637/user/1854 ,那么我的用户 id 就是 1854)。
冷知识:目前 OJ 里有 位用户。
这重要吗?
为什么是骗分的神区?
在我眼中,题目可以用这些做法:
- 暴力枚举
- 暴力搜索
- 古法打表
- STL 大法
- 口胡算法板子
总结:
稍微改了改再运行后:
一些著名(或抽象)题目
注:这道题中的“风井省”疑似福建省,“真卷省”疑似浙江省。
UOJ特别篇
游戏三部曲:Geometry Dash, To the moon, Quantum break
用户大推荐
注:请输入文本都是指巨佬或者是主页内容太杂的用户(内容一定要very very长)
:现在不能访问了……
:现在会用了。
但没完全会用
抄我八皇后我还没找你算账呢!!!
神奇小东西
如果你把这句倒着的话粘贴到记事本里,再用方向键移动光标,你就会发现,实际移动的方向和你按得键上的方向是相反的
健康指南
一:
每日一杯水,喝水很健康;
每昍二杯沝,喝沝很健康;
每晿三杯㴇,喝㴇更健康。
二:
每天耕耕田,劳动很健康;
每天耕耕畕,劳动很健康;
每天耕耕畾,劳动更健康。
学OI有感
温知识:这幅图不是我画的
更温的知识:这也不是我画的。
杂言
.----------.
/ \
_(.-. _...._ .-.)_
(_)`-' __()__ `-'(_) 这是 Forge,某个品牌的经典款。
(....__| FORGE|__....) 不过似乎动力不足,跟不上时代了。
| | ~~~~~~ | |
`-' `-'
,--. <__)
`- |________7
|`. |\
.--|. \ |.\--. 这是 Fabric,一辆非常轻便的自行车。
/ j \ `.7__j__\ \ 表现出色,就是载重量不大行。
| o | (o)____O) |
\ / J \ /
`---' `---'
.----------.
/ \
_(.-. _...._ .-.)_
(_)`-' __()__ `-'(_) 这是 NeoForge,Forge 的下一代车型。
(....__| NEO |__....) 不过性能仍待测试。
| | ~~~~~~ | |
`-' `-'
---------------------
| .●●●. |
| ● .● |
| .● | 这是 Quilt,一个百变箱。
| | 你也不知道里面有啥,反正非常多元化。
| ● |
---------------------
.=""=.
/ _ _ \
| d b |
\ /\ /
,/'-=\/=-'\,
/ / \ \ 这是 LiteLoader,一只很久很久以前的鸡。
| / \ | 轻得只能带上两片纸。
\/ \ / \/
'. .'
_|`~~`|_
/|\ /|\
--------------- 这是 Rift……
| | | | | 你谁?
---------------
这是 Sandbox……
不是你怎么还没出生就似了?DP 是什么?
那当然是——
DeePseek啦!
提示:本文并未涉及任何现实中的组织、协会,及其组织的比赛,文中的 次次付、嗯哦哎 等字眼均指 中国人民币协会(China CNY Federation,CCF)及其组织的 全国拥有人民币比赛(National Own CNY in Informatics,NOI)。
我chovy,嗯哦哎真是太难了!我刚进校门,金属探测仪就响了,保安说它探测到我有钢铁般的意志,我说我是新时代的保尔柯察金,保安才放我过去。进入第114考场,发现教室里仅仅有八百个监控,肚子的的讲话正在大屏幕上播放。然后,考试的时候因为全考场的人都写了 int mian,而发生了考场馆暴动。永不放水的嗯哦哎组织团队次次付也是非常迅速,直接就是一个螺旋升天,把 Bjarne Stroustrup 报答了一顿,随后告诉我们,他们要做“最肝精的奥赛”。我们是 爷们!!!,不甘示弱,直接就是一个 while(true),结果对面甩过来个“成绩单未上船,请烧后再试!”,……
V我50以开通喂哎劈看全文!
天冷极了,下着雪,又快黑了。这是一年的最后一次——也是最重要的奥赛。在这又冷又黑的晚上,一个光着头赤着脚的小女孩在电脑旁打着代码。她在考完试的时候还骗了一些分数,但是有什么用呢?那是一个很难的题——那么难,一向是AK IOI的人才能写的。她在家里复盘的时候,两个通知飞快地弹过来,吓得她把成绩单都不小心删除了。一份怎么也找不着,另一个备份叫一个蒟蒻捡起来拿着跑了。他说,将来他有了金牌可以拿它当模板。
小女孩只好复读着走,复习资料整得这一块那一块的。她的旧文件夹里兜着许多代码,手里还拿着一把。这一整天,谁也没找过她问一段代码,谁也没给过她一个AC的提示。
可怜的小女孩!她哆哆嗦嗦地向前学。WA落在她破旧的已经快要AFO的账号上,那寥寥无几的水题打成提单披在OJ上,看上去很好做,不过她没注意这些。每个Oier的电脑里都透出AK来,街上飘着一股NOI经典题目的香味,因为这是最后一次奥赛——她可忘不了这个。
她在一个水题的提交记录里坐下来,蜷着腿缩成一团。她觉得更冷了。她不敢回CSP-J,因为她没写对一个题目,没挣到一个分,爸爸一定会让她AFO的。再说,家里跟街上一样冷。他们头上只有个电脑,虽然最贵的显卡已经用生锈的螺丝和乱搭的线路修好了,但是散热风扇还是可以炸缸。
她的一双小手几乎冻僵了。啊,哪怕一个小小的AC,对她也是有好处的!她敢从成把的题目里抽出一个,在电脑上调好了程序,找一个AC,来暖和暖和自己的小手吗?她终于抽出了一个。哧!OJ燃起来了,AC显示出来了!她把小手拢在AC上。多么温暖多么明亮的提交记录啊,简直像一支小小的AK。这是一次奇异的提交!小女孩觉得自己好像站在一个NOI颁奖台上,展示板写着闪亮的标题和祝贺语,现场热闹的,令人兴奋的,多么舒服啊!哎,这是怎么回事呢?她刚把脚伸出去,想让脚也暖和一下,AC灭了,颁奖台不见了。她坐在那儿,手里只有一个写过了的int mian()。
她又擦了一个。题目燃起来了,发出亮光来了。亮光落在屏幕上,那儿忽然变得像薄纱那么透明,她可以一直看到教室里。桌上铺着金黄的奖牌,摆着精致的证书和礼物,填满了奖品的书包正挂在最显眼的位置。更妙的是这个书包从墙上跳下来,背上插着录取通知书和同学们的照片,摇摇摆摆地在地板上滑行着,一直向这个没看到过这些景象的小女孩前来。这时候,题目灭了,她面前只有一个等待输入的命令行窗口。
她又擦着了一个红题。这一回,她坐在美丽的大学门口下。这个大门,比她去年培训摸鱼时透过电脑上的浏览器看到的还要大,还要美。壮观的柱子上挂着无数的暖心的祝福,许多个美丽的多彩前程,跟挂在学校官网里的一个样,在向她眨眼睛。小女孩向它们伸出手去。这时候,红题又灭了。只见这景象越升越高,最后成了在天空中闪烁的算法。有一颗SPFA落下来了,在天空中划出了一道细长的绿光。
“有一个什么Oier快要AFO了。”小女孩说。唯一疼她的学长在役的时候告诉过她∶一颗算法落下来,就有一个Oier要飞升了。
她在墙上又擦着了一根题解。这一回,题解把周围全照亮了。学长出现在亮光里,是那么温和,那么慈爱。
“学长!”小女孩叫起来,“啊!请把我带走吧!我知道,题解一灭,您就会不见的,像那热闹的颁奖现场,精致的书包,美丽的大学一个样,就会不见的!”
她赶紧擦着了一大把题解,要把学长留住。一大把题解发出强烈的AC,照得跟tourist(注:Atcoder常年霸榜第一)一样明亮。学长从来没有像现在这样高大,这样美丽。学长把小女孩拉起来,搂在DP里。她们俩在光明和快乐中飞走了,越飞越高,飞到那没有寒冷,没有饥饿,也没有痛苦的Scratch竞赛里去了。
第二天清晨,这个小女孩坐在墙角里,两腮通红,嘴上带着微笑。她AFO了,在旧年的NOI举办前夕AFO了。新年的A+B升起来了,照在她小小的电脑上。小女孩坐在那儿,手里还捏着一把烧过了的作弊者名单,其中就有她。
“她想给自己暖和一下。”Oier们说。谁也不知道她曾经看到过多么美丽的东西,她曾经多么幸福,跟着学长一起走向Scratch中去。
甲亢哥在广东的某个建筑上时,一个本地的 黑粉 粉丝认出了他,并告诉他,Delay no more 这个句子不仅在甲亢哥那边有(意思是“不要再拖延了”),他们这边也有。
于是,甲亢哥在建筑上向外面大喊:“我 delay no more!!!”(他想马上逛完广东)
楼下听到的:我丢累老木!!!
荷兰曾经推出过一个广告,大致内容是:一个小女孩坐在购物车里,手指着前方,嘴里念叨着:“mama, die, die, die...”
这个句子在荷兰语中意为:妈妈,那个,那个,那个……
然而,在只会英语的人耳中,他们听到的则是……
“妈妈,死,死,死……”
中文神翻译:“妈妈,内个,内个,内个……”(不要让黑人听到……)
一个买馄饨的老板打算整个英文招牌,于是他用翻译器翻译后写道:“Chaos”。
几天后,一个顾客过来,发现了这个招牌,他便把招牌改成:“Chaoshou”。
这个笑话集谐音、英语、方言为一体,你能读出来算你厉害。
缺省源
#include <bits/stdc++.h>
#define rep(_i, _a, _b, _c) \
for (int _i = (_a); _i <= (_b); _i += (_c))
#define ll long long
using namespace std;
template<typename T = int> T read() {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
x = x * 10 + (ch - '0');
ch = getchar();
} while (ch >= '0' && ch <= '9');
return (x * f);
}
template<typename T> void read_nums(T *a, int start, int end) {
rep(i, start, end, 1)
a[i] = read<T>();
}
template<typename T> void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
write(x / 10);
putchar(x % 10 + '0');
}
template<typename T> void write_nums(T *a, int start, int end, char sep = ' ') {
rep(i, start, end, 1) {
write(a[i]);
if (i != end)
putchar(sep);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
return 0;
}生成随机数
C 风格随机数
使用 rand() 函数
该函数包含在 cstdlib 库中。
设置种子: srand(x),其中 为无符号整形类型的数(譬如 time(NULL))。
产生随机数:rand(),范围在 到 之间。使用 rand() % x + y 可以生成 到 之间的随机数,但是质量较差。
利用地址特性
new type 可从系统空闲内存空间得到一个新的某个 type 类型的地址。由于新的地址指向的内容不确定,所以我们可以利用这个特性来生成随机数。
代码:
template<typename T>
T _rand(T x) {
return (*(new T)) % x;
}这份代码可以得到一个 到 范围内的随机数,其数据类型为 T。
C++ 风格随机数
以下内容均包含在 random 库内,且该库需要 C++11。
使用 random_device 类
random_device 类可以生成一个随机数,调用方法为 _rand()(其中 _rand 是一个 random_device 类)。
该类生成的随机数在不同设备上的值可能是不同的,但是在一个设备上的值是不会改变的。
使用 mt19937 类
初始化与设置种子:mt19937 _rand(x),其中 为整形类型的数。
生成随机数:_rand(),其中 _rand 是一个 mt19937 类。生成区间内随机数类似于“ C 风格随机数”章中的“使用 rand() 函数”节里使用的方法。
使用 uniform_int_distribution 类
初始化与设置种子:uniform_int_distribution<type> _rand(a, b),其中 type 为任意整数数据类型, 和 则为 type 类型的数。
生成随机数:_rand(rand_type),其中 _rand 是一个 uniform_int_distribution 类,rand_type 为随机数生成器类型(如 mt19937,但一定要先定义该类型的变量)。它可以生成 到 (这两个常量已经在上文中提到过)之间的随机数。
使用 uniform_real_distribution 类
使用方法类似于 uniform_int_distribution 类,但是 和 为任意小数数据类型,生成的随机数也为一个小数随机数。
不正经的随机数(玄学)
程序开始运行后输入一个 (),随后程序每隔一秒输出一个在 区间内的伪随机数。
但是豆包告诉我这个程序超级烂
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
class my_rand { //随机数类
int seed; //随机数种子
int _calc1(int _x) { //随机数计算公式1
return (abs(((((_x ^ 0x4a) & (0x7ef ^ _x)) - (_x * 0x2ad)) & ((_x ^ 0x5e) + (0x2f & ((0x7ad | _x) & 0x2a) * 0xd1a))) * ((_x & 0x1a9) ^ (0xe7f | _x))));
}
int _calc2(int _x) { //随机数计算公式2
return (abs(((((_x ^ 0x7c) & (0x2a4 ^ _x)) - (_x * 0xfe1)) & ((_x ^ 0xa4) + (0xf1 & ((0x6ca | _x) & 0x5b) * 0x2ea))) * ((_x & 0x8eb) ^ (0xb3e | _x))));
}
int _calc3(int _x) { //随机数计算公式3
return (abs(((((_x ^ 0x3b) & (0x9ca ^ _x)) - (_x * 0x2df)) & ((_x ^ 0x7f) + (0x1a & ((0x2dc | _x) & 0x8e) * 0x5dc))) * ((_x & 0x7ea) ^ (0x3a7 | _x))));
}
int _calc4() { //随机数计算公式4
return (((_calc1(seed) ^ seed) & (_calc3(seed) ^ seed)) % ((_calc2(seed) + 1) ^ seed));
}
public:
void rseed() { //不加参数种子默认为当前时间
seed = time(NULL);
}
void rseed(int _seed) { //设置种子为_seed
seed = _seed;
}
my_rand() { rseed(); } // 初始化
my_rand(int _seed) { rseed(_seed); }
int operator ()() { //获取一个int范围内的随机数
rseed(_calc4() ^ time(NULL)); //重设种子
return _calc4();
}
int operator ()(int _x) { //获取一个小于x的随机数
rseed(_calc4() ^ time(NULL));
return (_calc4() % _x);
}
};
int main() {
my_rand _rand;
int x, rnd;
cin >> x;
while (1) {
rnd = _rand(x);
cout << rnd << '\n';
Sleep(1000); //等待一秒
}
return 0;
}玄学代码
1
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(rand());
int n = rand() % 2;
if (n) cout << "AC";
else cout << "WA";
return 0;
}这份也就会随机输出代码可以在这道题取得70分的好成绩!!!AC和WA的
2
#include <bits/stdc++.h>
#define _rep(_i) \
for (int _i : p)
using namespace std;
const int p[] = {2, 3, 5, 7};
int main() {
_rep(a)
_rep(b)
_rep(c)
_rep(d)
_rep(e)
_rep(f)
_rep(g)
_rep(h)
_rep(i)
_rep(j) {
int x = a * 1000 + b * 100 + c * 10 + d;
int y = e;
int z = f * 10000 + g * 1000 + h * 100 + i * 10 + j;
if (x * y == z)
printf("%d*%d=%d\n", x, y, z);
}
return 0;
}这份屎山代码可以在这道题取得100分的好成绩!!!
3
不可以,总司令!!!
#include <bits/stdc++.h>
#define rep(_i, _a, _b, _c) \
for (int _i = (_a); _i <= (_b); _i += (_c))
#define ll long long
using namespace std;
template<typename T> T read() {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
x = x * 10 + (ch - '0');
ch = getchar();
} while (ch >= '0' && ch <= '9');
return (x * f);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("galaxy.in", "r", stdin);
freopen("galaxy.out", "w", stdout);
int n = read<int>(), m = read<int>(), u, v, q;
while (m--) {
u = read<int>();
v = read<int>();
}
q = read<int>();
while (q--) {
puts("NO");
}
return 0;
}这份问啥只答代码可以在这道题中获得45分的好成绩!!!NO的
4
再说一遍:不可以,总司令!!!
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 3)
cout << 2;
else
puts("no");
return 0;
}这份只输出样例和代码可以在这道题中获得满分的好成绩!!!no的
5
转载该用户代码。
#include<bits/stdc++.h>
using namespace std;
int f,g,h,i;
int main()
{
cin>>f>>g>>h>>i;
cout<<max(f,g)/2<<'\n'<<max(h,i)/2<<'\n';
return 0;
}
这份使用神秘公式的代码可以在这道题中获得90分的好成绩!!!
Better ConsolePauser
ConsolePauser 是什么?
ConsolePauser.exe 是 DevC++ 等众多主流 C++ 便携式 IDE 在运行程序时给程序套的一层“壳”,在程序运行完后显示程序运行时的一些信息。
那为什么要写这个项目?
原本的 ConsolePauser.exe 界面显示的内容不全面,且缺乏 Oier 需要的内容,本项目因此而来。
使用方法
编译
编译时记得加上 -lpsapi,否则可能无法正常编译。
如 DevC++,点击“工具——编译选项”,勾选“编译时加入以下命令”,在下方输入框中加入 -lpsapi 即可。
使用
将程序编译后重命名为 ConsolePauser.exe,随后放入 IDE 安装目录中替换原来的程序。
此时使用 IDE 运行程序,应该就能正常使用 Better ConsolePauser 了。
代码
#include <windows.h>
#include <psapi.h>
#include <iostream>
#include <chrono>
#include <string>
#include <sstream>
using namespace std;
string formatDuration(const chrono::steady_clock::duration& duration) {
auto seconds = chrono::duration_cast<chrono::seconds>(duration);
auto milliseconds = chrono::duration_cast<chrono::milliseconds>(duration) % 1000;
ostringstream oss;
oss << seconds.count() << " 秒 " << milliseconds.count() << " 毫秒";
return oss.str();
}
string formatDurationMs(long long milliseconds) {
long long seconds = milliseconds / 1000;
long long ms = milliseconds % 1000;
ostringstream oss;
oss << seconds << " 秒 " << ms << " 毫秒";
return oss.str();
}
string showExitMessage(DWORD exitCode) {
string outString = "";
switch(exitCode) {
case 0:
outString += "正常退出";
break;
case 1:
outString += "一般错误";
break;
case 2:
outString += "文件未找到";
break;
case 3:
outString += "路径未找到";
break;
case 5:
outString += "拒绝访问";
break;
case 1073741819:
outString += "访问违规";
break;
case 3221225477:
outString += "栈溢出";
break;
}
if (outString != "")
outString = " 退出状态: " + outString;
return outString;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
cerr << "使用方法: ConsolePauserPlus.exe <exe程序名> [被调用程序参数...]" << endl;
system("pause");
return 1;
}
system("cls");
string commandLine;
for (int i = 1; i < argc; ++i) {
if (i > 1) commandLine += " ";
string arg = argv[i];
if (arg.find(' ') != string::npos && arg.front() != '"' && arg.back() != '"') {
commandLine += "\"" + arg + "\"";
} else {
commandLine += arg;
}
}
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi = { 0 };
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
BOOL bSuccess = CreateProcessA(
NULL,
const_cast<char*>(commandLine.c_str()),
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi
);
if (!bSuccess) {
cerr << "无法启动程序: " << commandLine << endl;
cerr << "错误代码: " << GetLastError() << endl;
system("pause");
return 1;
}
// 获取进程启动时的CPU时间
FILETIME createTime1, exitTime1, kernelTime1, userTime1;
GetProcessTimes(pi.hProcess, &createTime1, &exitTime1, &kernelTime1, &userTime1);
ULARGE_INTEGER kernelStart, userStart;
kernelStart.LowPart = kernelTime1.dwLowDateTime;
kernelStart.HighPart = kernelTime1.dwHighDateTime;
userStart.LowPart = userTime1.dwLowDateTime;
userStart.HighPart = userTime1.dwHighDateTime;
LONGLONG cpuStartTime = kernelStart.QuadPart + userStart.QuadPart;
// 记录墙上时钟开始时间
auto wallStartTime = chrono::steady_clock::now();
SIZE_T peakMemory = 0;
DWORD waitResult;
do {
waitResult = WaitForSingleObject(pi.hProcess, 50);
if (waitResult == WAIT_TIMEOUT) {
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(pi.hProcess, &pmc, sizeof(pmc))) {
SIZE_T current = pmc.WorkingSetSize / 1024;
if (current > peakMemory) {
peakMemory = current;
}
}
}
} while (waitResult == WAIT_TIMEOUT);
// 获取进程结束时的CPU时间
FILETIME createTime2, exitTime2, kernelTime2, userTime2;
GetProcessTimes(pi.hProcess, &createTime2, &exitTime2, &kernelTime2, &userTime2);
ULARGE_INTEGER kernelEnd, userEnd;
kernelEnd.LowPart = kernelTime2.dwLowDateTime;
kernelEnd.HighPart = kernelTime2.dwHighDateTime;
userEnd.LowPart = userTime2.dwLowDateTime;
userEnd.HighPart = userTime2.dwHighDateTime;
LONGLONG cpuEndTime = kernelEnd.QuadPart + userEnd.QuadPart;
// 计算CPU时间(毫秒)
LONGLONG cpuTime100ns = cpuEndTime - cpuStartTime;
long long cpuTimeMs = cpuTime100ns / 10000;
// 计算墙上时钟时间
auto wallEndTime = chrono::steady_clock::now();
auto wallTime = wallEndTime - wallStartTime;
DWORD exitCode;
GetExitCodeProcess(pi.hProcess, &exitCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
cout << "\n------------------------------------------------------------" << endl;
cout << "程序名称:" << argv[1] << endl;
cout << "CPU运行时间: " << formatDurationMs(cpuTimeMs) << endl;
cout << "墙上时钟时间 (即包含输入输出时间): " << formatDuration(wallTime) << endl;
if (peakMemory > 0) {
cout << "内存使用量 (峰值): " << peakMemory << " KB" << endl;
} else {
cout << "内存使用量: 无法获取 (进程可能已瞬间退出)" << endl;
}
cout << "退出代码: " << exitCode << " (十六进制代码: 0x" << hex << exitCode << showExitMessage(exitCode) << ")" << endl;
system("pause");
system("cls");
return 0;
}分数类型
食用指南:
#include <bits/stdc++.h>
#include "frac.h" //这个是包含分数类型的库,实际使用时请将代码复制到程序最前面
using namespace std;
using namespace __frac; //一定一定别忘写
int main() {
//我们定义一个分数f
frac f(2, 3); //第一个数为分子(必须大于0),第二个数为分母(必须大于0),现在f=2/3,也就是二分之三
//对了,如果定义时没有初始化,那么这个分数默认为1/1
f.reset(1, 2); //f被重设为了1/2
f = frac(1, 2); //与上面那条语句作用相同
f.reset(4, 6); f.rof(); //f被重设为了4/6,rof()作用是约分(一定化为最简分数)
cout << f << '\n'; //cout可以直接输出分数类型,输出为2/3
f = make_frac(7, 10); //make_frac()作用为创建一个分数,f现在为7/10
f.roftcd(2); //roftcd(int i)作用为将f的分子分母同时扩大为原来的i倍(也就是通分),现在f为14/20
cout << f.get_lcd(make_frac(1, 100)) << '\n'; //get_lcd(frac _f)作用为求f与1/100的最小公分母,输出为100
f.roftcd(make_frac(1, 100)); //将f与1/100通分
cout << f << '\n'; //输出为70/100
cout << f.get_rev() << '\n'; //get_rev()的返回值为f的倒数,输出为100/70
//cin >> f; cin可以直接输入分数f
f.reset(1, 2);
if (f == make_frac(1, 2)) //判断f是否等于1/2
cout << "YES\n";
else
cout << "NO\n";
//!=, <, >, <=, >=运算符使用方法同==
f = f + make_frac(1, 2); //将f设为f+1/2,-(需保证被减数>=减数), *, /运算符使用方法同+
//f += make_frac(1, 2); 与上面那条语句作用相同,-=, *=, /=运算符使用方法同+=
cout << f << '\n'; //分母为1时默认只输出分子,输出为1
//我们也可以设置f的一些参数
f.set_output_frac_to_vt(false); //当f可以化为整数时会以整数形式输出,默认为true(以整数形式输出,输出如1),这里设为了false(以正常分数形式输出,输出如1/1)
f.set_output_sep(' '); //输出f时分子与分母的间隔符号,默认为/(输出如1/2),这里设为了空格(输出如1 2)
//其它函数多半为frac定义时的内部函数,但确实有些用处,所以保留为public(get_gcd除外)
/*对了,frac类型也就是frac32类型,它的分子与分母为int类型。
其它还有frac64(long long类型)和frac16(short类型),这两个类型除了在使用make_frac函数时后面要加上位数(如make_frac64就是64位类型(long long)的对应函数)外,其余无区别。*/
return 0;
}
实现代码:
/*
Name: frac.h
Version: 1.1.1
Author: 2030chenxilin(YiskyGame)
From: SLYZOJ
*/
#include <utility>
#include <cassert>
#include <iostream>
#ifndef FRAC
#define FRAC
namespace __frac{
template<typename value_type>
class _frac{
// helper
typedef value_type vt;
vt get_gcd(vt _n, vt _m) {
vt __t;
while (_n != 0) {
__t = _m % _n;
_m = _n;
_n = __t;
}
return _m;
}
public:
// constructor
vt x, y;
_frac() : x(1), y(1) { }
_frac(const vt _x, const vt _y) : x(_x), y(_y) { assert(x > 0 && y > 0); }
_frac(const _frac& _f) : x(_f.x), y(_f.y) { assert(x > 0 && y > 0); }
_frac reset(const vt _x, const vt _y) {
assert(_x > 0 && _y > 0);
x = _x, y = _y;
return *this;
}
_frac reset(const _frac _f) {
return reset(_f.x, _f.y);
}
_frac operator =(const _frac _f) {
return reset(_f);
}
// reduction of fractions to a common denominator function & reduction of a fraction function
_frac get_rof() {
vt __g = get_gcd(x, y);
return _frac(x / __g, y / __g);
}
_frac rof() {
return reset(get_rof());
}
vt get_lcd(_frac _f) {
return y / get_gcd(y, _f.y) * _f.y;
}
_frac get_roftcd(vt _m) {
return _frac(x * _m, y * _m);
}
_frac roftcd(vt _m) {
return reset(get_roftcd(_m));
}
_frac get_roftcd(_frac _f) {
vt __lcd = get_lcd(_f);
return _frac(__lcd / y * x, __lcd);
}
_frac roftcd(_frac _f) {
return reset(get_roftcd(_f));
}
std::pair<_frac, _frac> get_all_roftcd(_frac _f) {
return std::make_pair(get_roftcd(_f), _f.get_roftcd(*this));
}
void all_roftcd(_frac &_f) {
std::pair<_frac, _frac> __p = get_all_roftcd(_f);
reset(__p.first), _f.reset(__p.second);
}
// the other calc function
_frac get_rev() {
return _frac(y, x);
}
vt to_vt() {
if (y == 1)
return x;
else
return -1;
}
// operator(comparson)
bool operator ==(_frac _f) {
_frac __f2 = _f;
all_roftcd(__f2);
return (x == __f2.x);
}
bool operator !=(_frac _f) {
return !(*this == _f);
}
bool operator <(_frac _f) {
_frac __f2 = _f;
all_roftcd(__f2);
return (x < __f2.x);
}
bool operator >(_frac _f) {
_frac __f2 = _f;
all_roftcd(__f2);
return (x > __f2.x);
}
bool operator <=(_frac _f) {
return (*this < _f || *this == _f);
}
bool operator >=(_frac _f) {
return (*this > _f || *this == _f);
}
// operator(calc, frac & frac)
_frac operator +(_frac _f) {
_frac __f2 = _f;
all_roftcd(__f2);
_frac __a = _frac(x + __f2.x, y);
return __a.get_rof();
}
_frac operator -(_frac _f) {
assert(*this >= _f);
_frac __f2 = _f;
all_roftcd(__f2);
_frac __a = _frac(x - __f2.x, y);
return __a.get_rof();
}
_frac operator *(_frac _f) {
_frac __a(x * _f.x, y * _f.y);
return __a.get_rof();
}
_frac operator /(_frac _f) {
return (*this * _f.get_rev());
}
// operator(calc, frac & vt)
#define new_operator_frac_and_vt(_op) \
_frac operator _op(vt _i) { \
return (*this _op _frac(_i, 1)); \
}
new_operator_frac_and_vt(+)
new_operator_frac_and_vt(-)
new_operator_frac_and_vt(*)
new_operator_frac_and_vt(/)
// operator(calc to)
#define new_operator_calc_to_frac_and_frac(_op, _op2) \
_frac operator _op(_frac _f) { \
*this = *this _op2 _f; \
return *this; \
}
#define new_operator_calc_to_frac_and_vt(_op, _op2) \
_frac operator _op(vt _i) { \
*this = *this _op2 _i; \
return *this; \
}
new_operator_calc_to_frac_and_frac(+=, +)
new_operator_calc_to_frac_and_frac(-=, -)
new_operator_calc_to_frac_and_frac(*=, *)
new_operator_calc_to_frac_and_frac(/=, /)
new_operator_calc_to_frac_and_vt(+=, +)
new_operator_calc_to_frac_and_vt(-=, -)
new_operator_calc_to_frac_and_vt(*=, *)
new_operator_calc_to_frac_and_vt(/=, /)
// set output
bool ofti = true;
char osep = '/';
void set_output_frac_to_vt(bool set = true) {
ofti = set;
}
void set_output_sep(char set = '/') {
osep = set;
}
};
// operator(input & output)
template<typename value_type>
std::istream& operator >>(std::istream& _in, _frac<value_type> &_f) {
char tmp;
_in >> _f.x >> tmp >> _f.y;
return _in;
}
template<typename value_type>
std::ostream& operator <<(std::ostream& _out, _frac<value_type> _f) {
if (_f.ofti && _f.to_vt() != -1)
_out << _f.to_vt();
else
_out << _f.x << _f.osep << _f.y;
return _out;
}
// typedef(and make a frac)
typedef _frac<int> frac32;
typedef frac32 frac;
typedef _frac<long long> frac64;
typedef _frac<short> frac16;
template<typename value_type>
_frac<value_type> _make_frac(value_type _x, value_type _y) {
return _frac<value_type>(_x, _y);
}
frac32 make_frac32(int _x, int _y) {
return _make_frac<int>(_x, _y);
}
frac make_frac(int _x, int _y) {
return make_frac32(_x, _y);
}
frac64 make_frac64(long long _x, long long _y) {
return _make_frac<long long>(_x, _y);
}
frac16 make_frac16(short _x, short _y) {
return _make_frac<short>(_x, _y);
}
}
#endif
八皇后打表做法
由于代码太长,放在这里了。
前面的区域,以后再来探索吧~
你为什么会看到这个?我看你真是闲的没事。
真的没有……?
:翻到这里了,看点动画吧!
:丸辣,怎么又被封了(
总字数:31443
非水字数(即人类可读的汉字内容):不想估计了
你看我干吗?




