• 个人简介

    #include<bits/stdc++.h>

    #include<windows.h>
    > #define VK_z 0x25
    > #define VK_x 0x28
    > #define VK_y 0x27
    > #define VK_u 0x26
    > #define VK_sh 0x20
    > #define VK_en 0x0D
    > using namespace std;
    > int fx=0,mx,my,jx,jy,len=-1,ttt=100;
    > bool sm,aajj,st,sss,_map_[100][100];
    > vector<long long> sx,sy;
    > void bs(int x,int y){
    > system("mode con cols= lines=50");
    > }
    > void winSize(int lines_height,int cols_width){
    > char cmd[100];
    > sprintf(cmd,"mode con cols=%d lines=%d",lines_height,cols_width);
    > system(cmd);
    > }
    > void aj(){
    > if(GetAsyncKeyState(VK_u)&&fx!=2&&aajj==0){
    > fx=1;
    > aajj=1;
    > }
    > if(GetAsyncKeyState(VK_x)&&fx!=1&&aajj==0){
    > fx=2;
    > aajj=1;
    > }
    > if(GetAsyncKeyState(VK_z)&&fx!=4&&aajj==0){
    > fx=3;
    > aajj=1;
    > }
    > if(GetAsyncKeyState(VK_y)&&fx!=3&&aajj==0){
    > fx=4;
    > aajj=1;
    > }
    > }
    > void go(int x,int y){
    > HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
    > COORD c={x,y};
    > SetConsoleCursorPosition(hOut,c);
    > }
    > void no(){
    > CONSOLE_CURSOR_INFO cursor_info={1,0};
    > SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
    > }
    > void COLOR(string c){
    > if(c=="GREEN") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
    > if(c=="RED") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
    > if(c=="BLUE") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
    > if(c=="YELLOW") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    > }
    > void _map(int x,int y){
    > if(sss==0){
    > COLOR("RED");
    > }
    > else{
    > COLOR("BLUE");
    > }
    > for(int i=2;i<=x*2+4;i=i+2){
    > go(i,2);
    > cout<<"■";
    > go(i,y+3);
    > cout<<"■";
    > Sleep(5);
    > }
    > for(int i=2;i<=y+3;i++){
    > go(2,i);
    > cout<<"■";
    > go(x*2+4,i);
    > cout<<"■";
    > Sleep(20);
    > }
    > }
    > void csh(int X,int Y){
    > COLOR("YELLOW");
    > int x=1,y=1;
    > while(x%2==1){
    > x=rand()%(X*2);
    > }
    > y=rand()%Y;
    > go(x+4,y+3);
    > cout<<"□";
    > sx.push_back(x+4);
    > sy.push_back(y+3);
    > }
    > void fs(){
    > COLOR("GREEN");
    > int l=40*2;
    > jx=1;
    > while(jx%2==1){
    > jx=rand()%l;
    > }
    > jy=rand()%40;
    > jy+=3;
    > jx+=4;
    > go(jx,jy);
    > cout<<"◎";
    > }
    > void yd(){
    > if(fx==1){
    > COLOR("YELLOW");
    > if(_map_[sx.back()][sy.back()-1]==1){
    > sm=1;
    > return;
    > }
    > if(sy.back()-1==2){
    > if(sss==0){
    > sm=1;
    > }
    > else{
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][my+2]=1;
    > sx.push_back(sx.back());
    > sy.push_back(my+2);
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > return;
    > }
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()-1]=1;
    > sx.push_back(sx.back());
    > sy.push_back(sy.back()-1);
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > if(fx==2){
    > COLOR("YELLOW");
    > if(_map_[sx.back()][sy.back()+1]==1){
    > sm=1;
    > return;
    > }
    > if(sy.back()+1==my+3){
    > if(sss==0){
    > sm=1;
    > }
    > else{
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(sx.back());
    > sy.push_back(3);
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > return;
    > }
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(sx.back());
    > sy.push_back(sy.back()+1);
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > if(fx==3){
    > COLOR("YELLOW");
    > if(_map_[sx.back()-2][sy.back()]==1){
    > sm=1;
    > return;
    > }
    > if(sx.back()-2==2){
    > if(sss==0){
    > sm=1;
    > }
    > else{
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(mx*2+2);
    > sy.push_back(sy.back());
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > return;
    > }
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(sx.back()-2);
    > sy.push_back(sy.back());
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > if(fx==4){
    > COLOR("YELLOW");
    > if(_map_[sx.back()+2][sy.back()]==1){
    > sm=1;
    > return;
    > }
    > if(sx.back()+2==mx*2+4){
    > if(sss==0){
    > sm=1;
    > }
    > else{
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(4);
    > sy.push_back(sy.back());
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > return;
    > }
    > go(sx.back()+1,sy.back());
    > cout<<"\b "<<" ";
    > go(sx.back(),sy.back());
    > cout<<"■";
    > _map_[sx.back()][sy.back()]=1;
    > sx.push_back(sx.back()+2);
    > sy.push_back(sy.back());
    > go(sx.back(),sy.back());
    > cout<<"□";
    > if(st!=0){
    > go(sx.front()+1,sy.front());
    > cout<<"\b "<<" ";
    > _map_[sx.front()][sy.front()]=0;
    > sx.erase(sx.begin()+0);
    > sy.erase(sy.begin()+0);
    > }
    > Sleep(ttt);
    > }
    > aajj=0;
    > }
    > int main(){
    > winSize(40,10);
    > srand(time(NULL));
    > go(12,1);
    > COLOR("GREEN");
    > cout<<"贪吃蛇";
    > go(11,3);
    > COLOR("RED");
    > cout<<"经典模式";
    > go(11,4);
    > COLOR("BLUE");
    > cout<<"无限模式";
    > go(6,6);
    > COLOR("YELLOW");
    > cout<<"--按下Enter后开始--";
    > sss=0;
    > go(9,4);
    > cout<<"\b ";
    > go(10,4);
    > cout<<"\b ";
    > go(8,3);
    > cout<<"=>";
    > while(!GetAsyncKeyState(VK_en)){
    > no();
    > if(GetAsyncKeyState(VK_x)&&sss!=1){
    > sss=1;
    > go(9,3);
    > cout<<"\b ";
    > go(10,3);
    > cout<<"\b ";
    > go(8,4);
    > cout<<"=>";
    > Sleep(100);
    > }
    > if(GetAsyncKeyState(VK_u)&&sss!=0){
    > sss=0;
    > go(9,4);
    > cout<<"\b ";
    > go(10,4);
    > cout<<"\b ";
    > go(8,3);
    > cout<<"=>";
    > Sleep(100);
    > }
    > }
    > my=40,mx=40;
    > Sleep(1000);
    > system("cls");
    > winSize(mx*3-10,my*2-35);
    > _map(mx,my);
    > csh(mx,my);
    > go(35,1);
    > cout<<"分数:";
    > while(1){
    > no();
    > aj();
    > if(st==0){
    > fs();
    > st=1;
    > len++;
    > COLOR("YELLOW");
    > go(41,1);
    > cout<<len;
    > }
    > COLOR("GREEN");
    > go(jx,jy);
    > cout<<"◎";
    > if(sx.back()==jx&&sy.back()==jy){
    > st=0;
    > }
    > yd();
    > if(sm==1){
    > break;
    > }
    > }
    > Sleep(1000);
    > system("cls");
    > winSize(40,10);
    > go(12,5);
    > cout<<"最终分数:"<<len;
    > Sleep(5000);
    > return 0;
    > }
    
    

    #include<windows.h> #define VK_z 0x25 #define VK_x 0x28 #define VK_y 0x27 #define VK_u 0x26 #define VK_sh 0x20 #define VK_en 0x0D using namespace std; int fx=0,mx,my,jx,jy,len=-1,ttt=100; bool sm,aajj,st,sss,map[100][100]; vector sx,sy; void bs(int x,int y){ system("mode con cols= lines=50"); } void winSize(int lines_height,int cols_width){ char cmd[100]; sprintf(cmd,"mode con cols=%d lines=%d",lines_height,cols_width); system(cmd); } void aj(){ if(GetAsyncKeyState(VK_u)&&fx!=2&&aajj0){ fx=1; aajj=1; } if(GetAsyncKeyState(VK_x)&&fx!=1&&aajj0){ fx=2; aajj=1; } if(GetAsyncKeyState(VK_z)&&fx!=4&&aajj0){ fx=3; aajj=1; } if(GetAsyncKeyState(VK_y)&&fx!=3&&aajj0){ fx=4; aajj=1; } } void go(int x,int y){ HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); COORD c={x,y}; SetConsoleCursorPosition(hOut,c); } void no(){ CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info); } void COLOR(string c){ if(c=="GREEN") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN); if(c=="RED") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); if(c=="BLUE") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE); if(c=="YELLOW") SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN); } void _map(int x,int y){ if(sss0){ COLOR("RED"); } else{ COLOR("BLUE"); } for(int i=2;i<=x2+4;i=i+2){ go(i,2); cout<<"■"; go(i,y+3); cout<<"■"; Sleep(5); } for(int i=2;i<=y+3;i++){ go(2,i); cout<<"■"; go(x2+4,i); cout<<"■"; Sleep(20); } } void csh(int X,int Y){ COLOR("YELLOW"); int x=1,y=1; while(x%21){ x=rand()%(X2); } y=rand()%Y; go(x+4,y+3); cout<<"□"; sx.push_back(x+4); sy.push_back(y+3); } void fs(){ COLOR("GREEN"); int l=402; jx=1; while(jx%21){ jx=rand()%l; } jy=rand()%40; jy+=3; jx+=4; go(jx,jy); cout<<"◎"; } void yd(){ if(fx1){ COLOR("YELLOW"); if(map[sx.back()][sy.back()-1]1){ sm=1; return; } if(sy.back()-12){ if(sss0){ sm=1; } else{ go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][my+2]=1; sx.push_back(sx.back()); sy.push_back(my+2); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } return; } go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()-1]=1; sx.push_back(sx.back()); sy.push_back(sy.back()-1); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } if(fx2){ COLOR("YELLOW"); if(map[sx.back()][sy.back()+1]1){ sm=1; return; } if(sy.back()+1my+3){ if(sss0){ sm=1; } else{ go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(sx.back()); sy.push_back(3); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } return; } go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(sx.back()); sy.push_back(sy.back()+1); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } if(fx3){ COLOR("YELLOW"); if(map[sx.back()-2][sy.back()]1){ sm=1; return; } if(sx.back()-22){ if(sss0){ sm=1; } else{ go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(mx*2+2); sy.push_back(sy.back()); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } return; } go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(sx.back()-2); sy.push_back(sy.back()); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } if(fx4){ COLOR("YELLOW"); if(map[sx.back()+2][sy.back()]1){ sm=1; return; } if(sx.back()+2mx2+4){ if(sss==0){ sm=1; } else{ go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(4); sy.push_back(sy.back()); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } return; } go(sx.back()+1,sy.back()); cout<<"\b "<<" "; go(sx.back(),sy.back()); cout<<"■"; map[sx.back()][sy.back()]=1; sx.push_back(sx.back()+2); sy.push_back(sy.back()); go(sx.back(),sy.back()); cout<<"□"; if(st!=0){ go(sx.front()+1,sy.front()); cout<<"\b "<<" "; map[sx.front()][sy.front()]=0; sx.erase(sx.begin()+0); sy.erase(sy.begin()+0); } Sleep(ttt); } aajj=0; } int main(){ winSize(40,10); srand(time(NULL)); go(12,1); COLOR("GREEN"); cout<<"贪吃蛇"; go(11,3); COLOR("RED"); cout<<"经典模式"; go(11,4); COLOR("BLUE"); cout<<"无限模式"; go(6,6); COLOR("YELLOW"); cout<<"--按下Enter后开始--"; sss=0; go(9,4); cout<<"\b "; go(10,4); cout<<"\b "; go(8,3); cout<<"=>"; while(!GetAsyncKeyState(VK_en)){ no(); if(GetAsyncKeyState(VK_x)&&sss!=1){ sss=1; go(9,3); cout<<"\b "; go(10,3); cout<<"\b "; go(8,4); cout<<"=>"; Sleep(100); } if(GetAsyncKeyState(VK_u)&&sss!=0){ sss=0; go(9,4); cout<<"\b "; go(10,4); cout<<"\b "; go(8,3); cout<<"=>"; Sleep(100); } } my=40,mx=40; Sleep(1000); system("cls"); winSize(mx3-10,my*2-35); _map(mx,my); csh(mx,my); go(35,1); cout<<"分数:"; while(1){ no(); aj(); if(st==0){ fs(); st=1; len++; COLOR("YELLOW"); go(41,1); cout<<len; } COLOR("GREEN"); go(jx,jy); cout<<"◎"; if(sx.back()==jx&&sy.back()jy){ st=0; } yd(); if(sm1){ break; } } Sleep(1000); system("cls"); winSize(40,10); go(12,5); cout<<"最终分数:"<<len; Sleep(5000); return 0; }

  • 通过的题目

  • 最近活动

  • 最近编写的题解

题目标签

分支问题
13
数组问题
11
基础问题
9
简单循环
9
字符串
6
需要找规律的循环
6
字符型
6
高精度算法
6
二维数组
5
递归
5
嵌套循环
3
递推
2
搜索
2
深搜
2
并查集
2
函数
2
贪心
1
容器 stack 进制转换
1
广搜
1
容器
1