• 个人简介

    有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。

    to be a winner,or not to be a winner. this is a question

    加我团队吧!

    点击加入

    我的洛谷账号

    创造你自己的成就!(如上)

    火车头

    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("inline")
    #pragma GCC optimize("-fgcse")
    #pragma GCC optimize("-fgcse-lm")
    #pragma GCC optimize("-fipa-sra")
    #pragma GCC optimize("-ftree-pre")
    #pragma GCC optimize("-ftree-vrp")
    #pragma GCC optimize("-fpeephole2")
    #pragma GCC optimize("-ffast-math")
    #pragma GCC optimize("-fsched-spec")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("-falign-jumps")
    #pragma GCC optimize("-falign-loops")
    #pragma GCC optimize("-falign-labels")
    #pragma GCC optimize("-fdevirtualize")
    #pragma GCC optimize("-fcaller-saves")
    #pragma GCC optimize("-fcrossjumping")
    #pragma GCC optimize("-fthread-jumps")
    #pragma GCC optimize("-funroll-loops")
    #pragma GCC optimize("-fwhole-program")
    #pragma GCC optimize("-freorder-blocks")
    #pragma GCC optimize("-fschedule-insns")
    #pragma GCC optimize("inline-functions")
    #pragma GCC optimize("-ftree-tail-merge")
    #pragma GCC optimize("-fschedule-insns2")
    #pragma GCC optimize("-fstrict-aliasing")
    #pragma GCC optimize("-fstrict-overflow")
    #pragma GCC optimize("-falign-functions")
    #pragma GCC optimize("-fcse-skip-blocks")
    #pragma GCC optimize("-fcse-follow-jumps")
    #pragma GCC optimize("-fsched-interblock")
    #pragma GCC optimize("-fpartial-inlining")
    #pragma GCC optimize("no-stack-protector")
    #pragma GCC optimize("-freorder-functions")
    #pragma GCC optimize("-findirect-inlining")
    #pragma GCC optimize("-fhoist-adjacent-loads")
    #pragma GCC optimize("-frerun-cse-after-loop")
    #pragma GCC optimize("inline-small-functions")
    #pragma GCC optimize("-finline-small-functions")
    #pragma GCC optimize("-ftree-switch-conversion")
    #pragma GCC optimize("-foptimize-sibling-calls")
    #pragma GCC optimize("-fexpensive-optimizations")
    #pragma GCC optimize("-funsafe-loop-optimizations")
    #pragma GCC optimize("inline-functions-called-once")
    #pragma GCC optimize("-fdelete-null-pointer-checks")
    
    

    插入排序

    #include<iostream>
    #include<cmath>
    using namespace std;
    int n,a[100005];
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	for(int i=1;i<=n;i++)
    	{
    		int j=i-1;
    		while(j>=1&&a[j]>a[j+1])
    		{
    			swap(a[j],a[j+1]);
    			j--;
    		}
    	}
    	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    	return 0;
    }
    

    堆排序

    #include<iostream>
    #include<cmath>
    using namespace std;
    int t,p[1000005],len;
    void push_up(int id)
    {
    	if(id/2==0)return;
    	if(p[id/2]>p[id])
    	{
    		swap(p[id/2],p[id]);
    		push_up(id/2);
    	}
    }
    void push_down(int id)
    {
    	int k=id;
    	if(id*2<=len&&p[id*2]<p[k])
    		k=id*2;
    	if(id*2+1<=len&&p[id*2+1]<p[k])
    		k=id*2+1;
    	if(id!=k)
    	{
    		swap(p[id],p[k]);
    		push_down(k);
    	}
    }
    int main()
    {
    	cin>>t;
    	while(t--)
    	{
    		int opt,x;
    		cin>>opt;
    		if(opt==1)
    		{
    			cin>>x;
    			p[++len]=x;
    			push_up(len);
    		}
    		else if(opt==2)
    		{
    			cout<<p[1]<<endl;
    		}
    		else
    		{
    			p[1]=p[len--];
    			push_down(1);
    		}
    	}
    	return 0;
    }
    

    归并排序

    #include<iostream>
    using namespace std;
    int n,a[100005],b[100005];
    void merger_sort(int l,int r)
    {
    	if(l>=r)return;
    	int mid=l+r>>1;
    	merger_sort(l,mid);
    	merger_sort(mid+1,r);
    	int x=l,L=l,y=mid+1;
    	while(x<=mid&&y<=r)
    	{
    		if(a[x]<=a[y])
    			b[l++]=a[x++];
    		else
    			b[l++]=a[y++];
    	}
    	while(x<=mid)
    		b[l++]=a[x++];
    	while(y<=r)
    		b[l++]=a[y++];
    	for(int i=L;i<=r;i++)
    		a[i]=b[i];
    }
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	merger_sort(1,n);
    	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    	return 0;
    }
    

    快速排序

    #include<iostream>
    using namespace std;
    int n,a[100005];
    int check(int l,int r)
    {
    	int k=l;
    	while(l<=r)
    	{
    		while(l<=r&&a[l]<=a[k])
    			l++;
    		while(l<=r&&a[r]>=a[k])
    			r--;
    		if(l<=r)
    			swap(a[l],a[r]);
    	}
    	swap(a[k],a[r]);
    	return r;
    }
    void quickly_sort(int l,int r)
    {
    	if(l>=r)return;
    	int mid=check(l,r);
    	quickly_sort(l,mid-1);
    	quickly_sort(mid+1,r);
    }
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	quickly_sort(1,n);
    	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    	return 0;
    }
    

    拓扑排序(还没学

    我的自创小游戏

    #include<iostream>
    #include<bits/stdc++.h>
    #include<ctime>
    #include<conio.h>
    #include<Windows.h>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
    	cout<<"请输入密码:"<<endl;
    	int mima;
    	cin>>mima;
    	if(mima!=123698745)
    	{
    		Sleep(5000);
    		cout<<"运行时间较长,请耐心等待反馈错误信息........."<<endl;
    		Sleep(2000);
    		system("pause");
    		system("pause");
    		system("pause");
    		return 0;
    	}
    	cout<<"请选择你的身份:"<<endl;
    	int sf;
    	cout<<"1.管理员 2.游客"<<endl;
    	cin>>sf;
    	bool flag=false;
    	if(sf==1)
    	{
    		cout<<"请输入您的名字、密码:"<<endl;
    		char name;
    		int mm;
    		cin>>name>>mm;
    		if(name=='H'&&mm==123123)
    		{
    			flag=true;
    			system("cls");
    			cout<<"Welcome!"<<endl;
    			Sleep(2000);
    			cout<<"在主程序中(非真正cmd)输入999可获得惊喜。"<<endl;
    			Sleep(2000);
    			system("cls");
    			system("cmd");
    		}
    		else if(name=='m'&&mm==123698745)
    		{
    			flag=true;
    			system("cls");
    			cout<<"Welcome!"<<endl;
    			Sleep(2000);
    			cout<<"在主程序中(非真正cmd)输入999可获得惊喜。"<<endl;
    			Sleep(2000);
    			system("cls");
    			system("cmd");
    		}
    		else
    		{
    			cout<<"错误!!您即将以游客身份进入。"<<endl;
    			Sleep(2000);
    		}
    	}
    	unsigned long long cz=0;
    	system("cls");
    	cout<<"作者衷心的提醒您,不要输入字符、字符串指令或过长的数字";
    	for(int i=1;i<=25;i++)
    	{
    		cout<<".";
    		Sleep(100);
    	}
    	cout<<endl;
    	while(1)
    	{
    		system("color 0F");
    		system("cls");
    		cout<<endl;
    		cout<<"----------cmd----------"<<endl;
    		cout<<"1.计算器"<<endl;
    		cout<<"2.关机程序"<<endl;
    		cout<<"3.草稿纸"<<endl;
    		cout<<"4.系统查询"<<endl;
    		cout<<"5.cmd后台"<<endl;
    		cout<<"6.帮助"<<endl;
    		cout<<"7.仿黑客"<<endl;
    		cout<<"8.游戏"<<endl;
    		cout<<"9.画图"<<endl;
    		cout<<"输入-1退出程序。"<<endl;
    		cout<<"----请输入序号进行操作:";
    		cin>>cz;
    		if(cz==-1)return 0;
    		if(cz==1)
    		{
    			system("cls");
    			cout<<"请问您需要系统计算机(1)还是简单计算机(2)?"<<endl;
    			int xz;
    			cout<<"请输入:";
    			cin>>xz;
    			if(xz==1)
    			{
    				system("calc");
    			}
    			else if(xz==2)
    			{
    				system("cls");
    				cout<<"-----简易计算机-----"<<endl;
    				int a,b;
    				while(1)
    				{
    					cout<<"请输入两个数(整数)(-1退出):";
    					cin>>a;
    					if(a==-1)break;
    					cin>>b;
    					cout<<endl;
    					cout<<"和:"<<a+b<<endl;
    					cout<<"差:"<<a-b<<endl;
    					cout<<"积:"<<a*b<<endl;
    					cout<<"商:"<<a/b<<endl;
    					cout<<"余:"<<a%b<<endl;
    					system("pause");
    					system("cls");
    				}
    			}
    		}
    		else if(cz==2)
    		{
    			char ch;
    			system("cls");
    			cout<<"你需要知道取消关机密码方可安全关机!!"<<endl;\
    			Sleep(1000);
    			cout<<"继续输入y,取消输入n"<<endl;
    			cin>>ch;
    			if(ch=='y')
    			{
    				system("shutdown -s -t 120");
    				for(int i=3;i>=1;i--)
    				{
    					int qx;
    					cout<<"若要取消关机输入密码,否则输入-1(你还有"<<i<<"次机会)"<<endl;
    					cin>>qx;
    					if(qx==-1)break;
    					else if(qx==123698745)
    					{
    						system("shutdown -a");
    						break;
    					}
    					else cout<<"错误!"<<endl;
    				}
    			}
    			else continue;
    		}
    		else if(cz==3)
    		{
    			system("notepad");
    		}
    		else if(cz==4)
    		{
    			system("ver");
    			system("pause");
    		}
    		else if(cz==5)
    		{
    			system("cls");
    			system("cmd");
    		}
    		else if(cz==6)
    		{
    			cout<<"以下是cmd后台的指令:"<<endl;
    			system("pause");
    			system("help");
    			system("pause");
    		}
    		else if(cz==7)
    		{
    			system("cls");
    			cout<<"输入时间(建议100以上,否则太短):"<<endl;
    			int time;
    			cin>>time;
    			if(time%2==0)system("color 0a");
    			else system("color 0c");
    			for(int i=0;i<=time;i++)
    			{
    				cout<<"01001010010001011110101110101010001111110101";
    			}
    			system("pause");
    			system("color 0F");
    		}
    		else if(cz==8)
    		{
    			system("cls");
    			cout<<"请选择游戏:"<<endl;
    			int game;
    			cout<<"1.石头剪刀布   2.迷宫  3.问答小游戏"<<endl;
    			cin>>game;
    			if(game==1)
    			{
    				srand(time(0));
    				int sjb=0;
    				while(1)
    				{
    					system("cls");
    					cout<<"计算机已经想好了它要出的种类。"<<endl;
    					Sleep(1000);
    					cout<<"现在你来选择:1.石头  2.剪刀  3.布(-1退出)"<<endl;
    					cin>>sjb;
    					if(sjb==-1)break;
    					int cmt=rand()%3+1;
    					if(sjb==1)
    					{
    						switch(cmt)
    						{
    							case 1:cout<<"平局!计算机出"<<cmt<<endl,system("pause");break;
    							case 2:cout<<"你赢了!计算机出"<<cmt<<endl,system("pause");break;
    							case 3:cout<<"你输了!计算机出"<<cmt<<endl,system("pause");break;
    						}
    					}
    					if(sjb==2)
    					{
    						switch(cmt)
    						{
    							case 2:cout<<"平局!计算机出"<<cmt<<endl,system("pause");break;
    							case 3:cout<<"你赢了!计算机出"<<cmt<<endl,system("pause");break;
    							case 1:cout<<"你输了!计算机出"<<cmt<<endl,system("pause");break;
    						}
    					}
    					if(sjb==3)
    					{
    						switch(cmt)
    						{
    							case 3:cout<<"平局!计算机出"<<cmt<<endl,system("pause");break;
    							case 1:cout<<"你赢了!计算机出"<<cmt<<endl,system("pause");break;
    							case 2:cout<<"你输了!计算机出"<<cmt<<endl,system("pause");break;
    						}
    					}
    				}
    			}
    			else if(game==2)
    			{
    				char map[15][15]={{'-','-','-','-','-','-','-','-','-','-'},
    								 {'|','0',' ',' ',' ','#',' ','#','#','|'},
    								 {'|',' ',' ','#',' ','#',' ','#',' ','|'},
    								 {'|','#',' ','#',' ',' ',' ',' ','#','|'},
    								 {'|',' ',' ','#',' ','#',' ','#','#','|'},
    								 {'|','#','#',' ','#',' ',' ',' ','#','|'},
    								 {'|',' ','#',' ',' ',' ','#','#',' ','|'},
    								 {'|',' ',' ',' ','#','#','#','#','#','|'},
    								 {'|','#',' ','#',' ',' ',' ','#','#','|'},
    								 {'|','#',' ',' ',' ','#',' ',' ','E','|'},
    								 {'-','-','-','-','-','-','-','-','-','-'}};
    				char ch,st;
    				int sx,sy,ex,ey;
    				sx=1,sy=1,ex=9,ey=8;
    				system("cls");
    				cout<<"欢迎来到迷宫游戏!!"<<endl;
    				Sleep(1000);
    				cout<<"wasd分别是上左下右"<<endl;
    				Sleep(1000);
    				cout<<"输入y开始,n取消"<<endl;
    				cin>>st;
    				if(st!='y')continue;
    				system("cls");
    				cout<<"0是你,E是终点,空格是路,#是墙壁,-/|是边界"<<endl;
    				for(int i=0;i<11;i++)
    				{
    					for(int j=0;j<=10;j++)
    					{
    						cout<<map[i][j];
    					}
    					cout<<endl;
    				}
    				while(1)
    				{
    					ch=getch();
    					if(ch=='w')
    					{
    						if(map[sx-1][sy]!='-'&&map[sx-1][sy]!='#')
    							map[sx][sy]=' ',map[--sx][sy]='0';
    					}
    					else if(ch=='s')
    					{
    						if(map[sx+1][sy]!='-'&&map[sx+1][sy]!='#')
    							map[sx][sy]=' ',map[++sx][sy]='0';
    					}
    					else if(ch=='a')
    					{
    						if(map[sx][sy-1]!='|'&&map[sx][sy-1]!='#')
    							map[sx][sy]=' ',map[sx][--sy]='0';
    					}
    					else if(ch=='d')
    					{
    						if(map[sx][sy+1]!='|'&&map[sx][sy+1]!='#')
    							map[sx][sy]=' ',map[sx][++sy]='0';
    					}
    					if(sx==ex&&sy==ey)break;
    					system("cls");
    					cout<<"0是你,E是终点,空格是路,#是墙壁,-/|是边界"<<endl;
    					for(int i=0;i<11;i++)
    					{
    						for(int j=0;j<=10;j++)
    						{
    							cout<<map[i][j];
    						}
    						cout<<endl;
    					}
    				}
    				system("cls");
    				system("color 6E");
    				cout<<"你赢了!!!"<<endl;
    				system("pause");
    				system("color 0F");
    			}
    			else if(game==3)
    			{
    				system("cls");
    				cout<<"问答小游戏"<<endl;
    				system("pause");
    				if(MessageBox(NULL,("要继续吗?"),("问答小游戏"),MB_YESNO)==IDNO)return 0;
    				MessageBox(NULL,("好的!"),("问答小游戏"),MB_OK);
    				while(MessageBox(NULL,("1+1=2"),("问题1"),MB_ICONQUESTION|MB_YESNO)!=IDYES)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("问题1"),MB_ICONINFORMATION|MB_RETRYCANCEL)==IDRETRY)continue;
    					else
    					{
    						MessageBox(NULL,("错误!"),("游戏结束"),MB_ICONSTOP|MB_OK);
    						return 0;
    					}
    				}
    				MessageBox(NULL,("答对了!"),("恭喜"),MB_OK);
    				while(MessageBox(NULL,("BDFS是指广搜"),("问题2"),MB_ICONQUESTION|MB_YESNO)!=IDNO)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("问题2"),MB_ICONINFORMATION|MB_RETRYCANCEL)==IDRETRY)continue;
    					else
    					{
    						MessageBox(NULL,("错误!"),("游戏结束"),MB_ICONSTOP|MB_OK);
    						return 0;
    					}
    				}
    				MessageBox(NULL,("你真厉害"),("恭喜"),MB_OK);
    				MessageBox(NULL,("关卡题"),("警告"),MB_ICONEXCLAMATION|MB_OK);
    				while(MessageBox(NULL,("你是个蒟蒻"),("问题3"),MB_ICONQUESTION|MB_YESNO)!=IDYES)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("问题3"),MB_ICONINFORMATION|MB_RETRYCANCEL)==IDRETRY)continue;
    					else
    					{
    						MessageBox(NULL,("恭喜大神成功跳关!"),("游戏结束"),MB_OK);
    						return 0;
    					}
    				}
    				MessageBox(NULL,("游戏结束后我会嘲讽并踩爆你"),("嘿嘿嘿"),MB_OK);
    				if(MessageBox(NULL,("要关机吗"),("问题4"),MB_ICONQUESTION|MB_YESNOCANCEL)==IDYES)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("问题4"),MB_ICONINFORMATION|MB_YESNO)==IDYES)
    					{
    						MessageBox(NULL,("好的!"),("要关机了"),MB_OK);
    						system("shutdown -s -t 120");
    						return 0;
    					}
    					else MessageBox(NULL,("好的!"),("不关机了"),MB_OK);
    				}
    				else if(MessageBox(NULL,("要关机吗"),("问题4"),MB_ICONQUESTION|MB_YESNOCANCEL)==IDNO)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("问题4"),MB_ICONINFORMATION|MB_YESNO)==IDYES)
    					{
    						MessageBox(NULL,("好的!"),("不关机了"),MB_OK);
    					}
    					else if(MessageBox(NULL,("是关还是不关?"),("???"),MB_ICONINFORMATION|MB_YESNO)==IDNO)
    						MessageBox(NULL,("好的!"),("不关机了"),MB_OK);
    					else
    					{
    						MessageBox(NULL,("好的!"),("要关机了"),MB_OK);
    						system("shutdown -s -t 120");
    						return 0;
    					}
    				}
    				MessageBox(NULL,("boss题"),("警告"),MB_ICONEXCLAMATION|MB_OK);
    				while(MessageBox(NULL,("ikun会打篮球"),("ikun"),MB_ICONQUESTION|MB_YESNO)!=IDYES)
    				{
    					if(MessageBox(NULL,("你确定吗?"),("ikun"),MB_ICONINFORMATION|MB_YESNO)==IDYES)
    					{
    						MessageBox(NULL,("错误!"),("ikun"),MB_ICONSTOP|MB_OK);
    						for(int i=1;i<=10;i++)
    						{
    							MessageBox(NULL,("鸡你太美"),("ikun"),MB_ICONEXCLAMATION|MB_OK);
    						}
    						return 0;
    					}
    				}
    				MessageBox(NULL,("over"),("over"),MB_OK);
    			}
    		}
    		else if(cz==9)
    		{
    			system("mspaint");
    		}
    		else if(cz==999&&flag)
    		{
    			system("cls");
    			for(int i=1;i<=130;i++)
    			{
    				cout<<(char)(i);
    				Sleep(150);
    			}
    			cout<<endl;
    			system("pause");
    		}
    		else cout<<"该指令不存在!!"<<endl,system("pause");
    	}
    }
    

    生成nn个随机数(10个一行)

    #include<iostream>
    #include<ctime>
    #include<stdlib.h>
    using namespace std;
    int n,cnt;
    int main()
    {
    	srand(time(0));
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cnt++;
    		cout<<rand()%10000+1<<" ";
    		if(cnt==10)
    		{
    			cnt=0;
    			cout<<endl;
    		}
    	}
    	return 0;
    }
    
  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

  • Stat

  • Rating

题目标签

系统测试
1
搜索
1
福建省历届夏令营
1
广度优先搜索
1
BFS
1
深度优先搜索
1
DFS
1