正文
增加 69 行删除 11 行
16 行未改动171819202122232424 行未改动4950515253545556575859606 行未改动6768697071727374169 行未改动全部展开2442452462472482492502513 行未改动25525625725825926026126211 行未改动2742752762772782792802812822832842852862872882892902912922932942955 行未改动30130230330430530630730830931031131231321 行未改动3353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653668 行未改动3753763773783793803813823833843853863873883893903913922 行未改动16 行未改动- 10/5: improved point mechanism- 10/6: fixed bugs after sand shift# Code```cpp//Pyramid Created by seanli1008 on 2025/10/3.24 行未改动for(int i=1;i<=20;i++){for(int j=1;j<=20;j++){if(edx==i && edy==j)cout<<"! ";else if(i==1 && j==1)cout<<"S ";else if(maze[i][j]==1 || maze[i][j]==2)cout<<". ";elsecout<<"# ";}cout<<endl;6 行未改动queue<pair<int,int>> que;memset(dis,0x3f,sizeof(dis));memset(visited,false,sizeof(visited));dis[1][1]=0;que.push({1,1});while(!que.empty()){auto cur=que.front();que.pop();169 行未改动全部展开//cout<<"Obstacles added: "<<endl;//cout<<dis[edx][edy]<<endl;//debug();//=== generate obstacles to add difficulty ===}void print(){for(int i=1;i<=20;i++){for(int j=1;j<=20;j++){3 行未改动else if(i==edx && j==edy)cout<<"! ";else if(maze[i][j]==0)cout<<"# ";elsecout<<". ";}else11 行未改动system("cls");cout<<"If you don't know the rules, enter 'R' to check. If you knew the rule, please enter 'S' to start the game. "<<endl;string op;cin>>op;Sleep(1000);system("cls");if(op=="R"){cout<<"You are a treasure hunter. There is a priceless treasure in this pyramid. Please find it. "<<endl;Sleep(1000);cout<<"However, it's really dark. you can only see things near you. It's garunteed that you can get the treasure. "<<endl;Sleep(1000);cout<<"What's even worse, the pyramid will change its map completely every 30s. "<<endl;cout<<"You'd better find the treasure in 30s or you will be sent to the entrance and you have to explore again. "<<endl;Sleep(1000);cout<<"Use up/down/left/right to move. '#' stands for wall and '.' stands for land. "<<endl;cout<<"o is yourself. ! stands for treasure. "<<endl;Sleep(1000);cout<<"If you understand the rules, enter 'ready' to start the game. "<<endl;string _;cin>>_;if(_!="ready")return 0;5 行未改动Sleep(200);generate_map();system("cls");//debug();x=1,y=1;int cnt=0;auto start=chrono::high_resolution_clock::now();while(x!=edx || y!=edy){print();int op;while(true){if(_kbhit()){int ch=_getch();21 行未改动if(op==1){//upif(is_valid(x-1,y) && maze[x-1][y]!=3 && maze[x-1][y]!=0){x--;cnt++;}}else if(op==2){//downif(is_valid(x+1,y) && maze[x+1][y]!=3 && maze[x+1][y]!=0){x++;cnt++;}}else if(op==3){//leftif(is_valid(x,y-1) && maze[x][y-1]!=3 && maze[x][y-1]!=0){y--;cnt++;}}else{//rightif(is_valid(x,y+1) && maze[x][y+1]!=3 && maze[x][y+1]!=0){y++;cnt++;}}system("cls");auto end=chrono::high_resolution_clock::now();auto duration=chrono::duration_cast<std::chrono::microseconds>(end-start);if(duration.count()>=30000000.0){cout<<"The sands under you starts shifting..."<<endl;cout<<"The sands under you starts shifting..."<<endl;cout<<"The sands under you starts shifting..."<<endl;cout<<"The Whole Map: "<<endl;8 行未改动bfs(0,0);cnt=0;start=chrono::high_resolution_clock::now();}}auto end=chrono::high_resolution_clock::now();auto duration=chrono::duration_cast<std::chrono::microseconds>(end-start);cout<<"WoW! You find the treasure! Congratulations!"<<endl;cout<<"Your time: "<<duration.count()/1000000.0<<"s"<<endl;cout<<"Your total step: "<<cnt<<endl;double mn_time=(double)dis[edx][edy]/3.0;double pts=((mn_time/(duration.count()/1000000.0))*100.0+((double)dis[edx][edy]/2.0)/((double)cnt/2.0)*100.0)/2;cout<<"Your point: "<<fixed<<setprecision(2)<<min(pts,100.0)<<"/100"<<endl;cout<<"Standard time (only for reference): "<<mn_time<<'s'<<endl;cout<<"Shortest Path: "<<dis[edx][edy]<<endl;cout<<"The Whole Map: "<<endl;debug();return 0;2 行未改动16 行未改动17181920212223242526272824 行未改动53545556575859606162636465666 行未改动737475767778798081169 行未改动全部展开2512522532542552562572582592602612622632642652662673 行未改动27127227327427527627727827928011 行未改动2922932942952962972982993003013023033043053063073083093103113123133143155 行未改动32132232332432532632732832933033133233333433533633733833934021 行未改动3623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124138 行未改动4224234244254264274284294304314324334344354364374384394404414424434444454464474484494502 行未改动16 行未改动- 10/5: improved point mechanism- 10/6: fixed bugs after sand shift- 10/10: added new mechanism: map- 10/10: fixed some bugs & improved gaming experience# Code```cpp//Pyramid Created by seanli1008 on 2025/10/3.24 行未改动for(int i=1;i<=20;i++){for(int j=1;j<=20;j++){if(edx==i && edy==j)cout<<"! ";else if(x==i && y==j)cout<<"o ";else if(maze[i][j]==1 || maze[i][j]==2)cout<<". ";else if(maze[i][j]==666)cout<<"M ";elsecout<<"# ";}cout<<endl;6 行未改动queue<pair<int,int>> que;memset(dis,0x3f,sizeof(dis));memset(visited,false,sizeof(visited));dis[1][1]=0;visited[1][1]=true;que.push({1,1});while(!que.empty()){auto cur=que.front();que.pop();169 行未改动全部展开//cout<<"Obstacles added: "<<endl;//cout<<dis[edx][edy]<<endl;//debug();//=== generate obstacles to add difficulty ===//=== random map pick_up ===int mp_pos_x=rnd()%20+1,mp_pos_y=rnd()%20+1;int surprisingly_hahaha=rnd()%2;while(maze[mp_pos_x][mp_pos_y]==0 || abs(mp_pos_x-edx)+abs(mp_pos_y-edy)<=10 || maze[mp_pos_x][mp_pos_y]==surprisingly_hahaha){mp_pos_x=rnd()%20+1;mp_pos_y=rnd()%20+1;}maze[mp_pos_x][mp_pos_y]=666;//=== random map pick_up ===}void print(){for(int i=1;i<=20;i++){for(int j=1;j<=20;j++){3 行未改动else if(i==edx && j==edy)cout<<"! ";else if(maze[i][j]==0)cout<<"# ";else if(maze[i][j]==666)cout<<"M ";elsecout<<". ";}else11 行未改动system("cls");cout<<"If you don't know the rules, enter 'R' to check. If you knew the rule, please enter 'S' to start the game. "<<endl;string op;cin>>op;Sleep(300);system("cls");if(op=="R"){cout<<"You are a treasure hunter. There is a priceless treasure in this pyramid. Please find it. "<<endl;Sleep(1000);cout<<"However, it's really dark. you can only see things near you. It's garunteed that you can get the treasure. "<<endl;Sleep(1000);cout<<"What's even worse, the pyramid will change its map completely every 20s. "<<endl;cout<<"You'd better find the treasure in 20s or you will be sent to the entrance and you have to explore again. "<<endl;Sleep(1000);cout<<"Luckily, there's a map in the pyramid. You can pick up the map and see the whole pyramid for 3s. "<<endl;Sleep(1000);cout<<"Use up/down/left/right to move. '#' stands for wall and '.' stands for land. "<<endl;cout<<"o is yourself. ! stands for treasure. "<<endl;Sleep(1000);cout<<"If you understand the rules, enter 'ready' to start the game. Good Luck!"<<endl;string _;cin>>_;if(_!="ready")return 0;5 行未改动Sleep(200);generate_map();system("cls");//debug();//Sleep(5000);//system("cls");x=1,y=1;int cnt=0;auto start=chrono::high_resolution_clock::now();std::chrono::high_resolution_clock::time_point mp_start;bool have_map=false,bonus=false;while(x!=edx || y!=edy){if(!have_map)print();elsedebug();int op;while(true){if(_kbhit()){int ch=_getch();21 行未改动if(op==1){//upif(is_valid(x-1,y) && maze[x-1][y]!=3 && maze[x-1][y]!=0){x--;cnt++;if(maze[x][y]==666 && !bonus){mp_start=chrono::high_resolution_clock::now();have_map=true;bonus=true;}}}else if(op==2){//downif(is_valid(x+1,y) && maze[x+1][y]!=3 && maze[x+1][y]!=0){x++;cnt++;if(maze[x][y]==666 && !bonus){mp_start=chrono::high_resolution_clock::now();have_map=true;bonus=true;}}}else if(op==3){//leftif(is_valid(x,y-1) && maze[x][y-1]!=3 && maze[x][y-1]!=0){y--;cnt++;if(maze[x][y]==666 && !bonus){mp_start=chrono::high_resolution_clock::now();have_map=true;bonus=true;}}}else{//rightif(is_valid(x,y+1) && maze[x][y+1]!=3 && maze[x][y+1]!=0){y++;cnt++;if(maze[x][y]==666 && !bonus){mp_start=chrono::high_resolution_clock::now();have_map=true;bonus=true;}}}system("cls");auto end=chrono::high_resolution_clock::now();auto duration=chrono::duration_cast<std::chrono::microseconds>(end-start);if(duration.count()>=20000000.0){cout<<"The sands under you starts shifting..."<<endl;cout<<"The sands under you starts shifting..."<<endl;cout<<"The sands under you starts shifting..."<<endl;cout<<"The Whole Map: "<<endl;8 行未改动bfs(0,0);cnt=0;start=chrono::high_resolution_clock::now();}auto mp_end=chrono::high_resolution_clock::now();auto mp_duration=chrono::duration_cast<std::chrono::microseconds>(mp_end-mp_start);if(mp_duration.count()>3000000.0)have_map=false;}auto end=chrono::high_resolution_clock::now();auto duration=chrono::duration_cast<std::chrono::microseconds>(end-start);cout<<"WoW! You find the treasure! Congratulations!"<<endl;cout<<"Your time: "<<duration.count()/1000000.0<<"s"<<endl;cout<<"Your total step: "<<cnt<<endl;double mn_time=0.0;if(bonus)mn_time=(double)dis[edx][edy]/3.5;elsemn_time=(double)dis[edx][edy]/3.0;double pts=((mn_time/(duration.count()/1000000.0))*100.0+((double)dis[edx][edy]/2.0)/((double)cnt/2.0)*100.0)/2;if(bonus)pts+=5.0;pts=min(pts,100.0);cout<<"Your point: "<<fixed<<setprecision(2)<<pts<<"/100"<<endl;cout<<"Standard time (only for reference, not very accurate): "<<mn_time<<'s'<<endl;cout<<"Shortest Path: "<<dis[edx][edy]<<endl;cout<<"The Whole Map: "<<endl;debug();return 0;2 行未改动