跳到正文

剪贴板

剪贴板 ovprirsh

原文
剪贴板信息

剪贴板信息

收录
更新

binary_search(单人/多人)(思维类)

C++
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
const int N=1e3+5;
map<string,int> dan;
map<string,int> duo;
signed main(){
	//HAPPY!
	srand(time(0));
	while(1){
		while(1){
			cout<<"开始Y(Yes)/N(No)/Q(query)\n";
			char c;
			cin>>c;
			if(c=='Y'){
				break;
			}
			else if(c=='N'){
				cout<<"bye bye\n";
				return 0;
			}
			else if(c=='Q'){
				cout<<"名字\n";
				string s;
				cin>>s;
				cout<<s<<"\n单人比赛分为:"<<dan[s]<<"\n多人比赛分为:"<<duo[s]<<endl;
				Sleep(2000);
				system("cls");
			}
			else{
				cout<<"错误\n";
			}
		}
		int op;
		while(1){
			cout<<"单人[找数字](1)/多人[数字炸弹](2)\n";
			char c;
			cin>>c;
			if(c=='1'){
				op=1;
				break;
			}
			else if(c=='2'){
				op=2;
				break;
			}
			else{
				cout<<"错误\n";
			}
		}
		if(op==1){
			cout<<"名字\n";
			string s;
			cin>>s;
			int x=rand()%(100)+1;
			int cnt=0;
			int mn=1,mx=100;
			while(1){
				cout<<mn<<"~"<<mx<<endl;
				int num;
				cin>>num;
				cnt++;
				if(num==x){
					cout<<"yes\n";
					cout<<"次数为:"<<cnt<<endl;
					if(cnt==1){
						dan[s]+=10;
						cout<<"加10分\n";
					}
					if(cnt==2){
						dan[s]+=8;
						cout<<"加8分\n";
					}
					if(cnt==3){
						dan[s]+=6;
						cout<<"加6分\n";
					}
					if(cnt==4){
						dan[s]+=5;
						cout<<"加5分\n";
					}
					if(cnt==5){
						dan[s]+=3;
						cout<<"加3分\n";
					}
					if(cnt==6){
						dan[s]++;
						cout<<"加1分\n";
					}
					if(cnt==7){
						dan[s]-=2;
						cout<<"减2分\n";
					}
					if(cnt>7){
						dan[s]-=4;
						cout<<"减4分\n";
					}
					Sleep(2000);
					system("cls");
					break;
				}
				if(num<x){
					mn=max(mn,num+1);
				}
				else{
					mx=min(mx,num-1);
				}
			}
		}
		else{
			cout<<"多少人?\n";
			int n;
			cin>>n;
			cout<<"名字\n";
			string s[N];
			for(int i=1;i<=n;i++){
				cin>>s[i];
			}
			int id=rand()%(n);
			int x=rand()%(100)+1;
			int mn=1,mx=100;
			bool boom=0;
			cout<<s[id+1]<<"先\n";
			while(1){
				if(boom){
					break;
				}
				id++;
				if(id==n+1){
					id=1;
				}
				cout<<"到"<<s[id]<<"走了\n";
				while(1){
					cout<<mn<<"~"<<mx<<endl;
					int num;
					cin>>num;
					system("cls");
					if(num==x){
						cout<<"boom!\n";
						for(int i=1;i<=n;i++){
							if(i==id){
								duo[s[i]]-=10;
							}
							else{
								duo[s[i]]+=5;
							}
						}
						boom=1;
						break;
					}
					if(num>=mn && num<=mx){
						if(num<x){
							mn=max(mn,num+1);
						}
						else{
							mx=min(mx,num-1);
						}
						break;
					}
					else{
						cout<<"错误\n";
					}
				}
			}
		}
	}
	return 0;
}