跳到正文

Wang_Chun1024

951440

.

在洛谷打开
资料、奖项与版本

资料

编号
951440
抓取

奖项

2025 CSP-J
一等奖
284 分 · 第 4998 名
2025 CSP-S
二等奖
118 分 · 第 6838 名
i2=−1,求∑n=12026in i^2=-1,求 \sum_{n=1}^{2026} i^n

课件

C++
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
HANDLE handle = GetStdHandle( STD_OUTPUT_HANDLE );
bool v[30][30], t[30][30];
int nums[30][30], n;
int x[] {0, -1, -1, -1, 0, 0, 1, 1, 1};
int y[] {0, -1, 0, 1, -1, 1, -1, 0, 1};
bool check( string s ) {
	if ( s.size() != 2 )
		return 0;
		
	if ( s[0] >= '0' && s[0] <= '9' && s[1] >= '0' && s[1] <= '9' )
		return 1;
		
	return 0;
}

void search( int a, int b ) {
	for ( int i = 1; i <= 8; i++ )
		if ( v[a + x[i]][b + y[i]] == 0 && nums[a + x[i]][b + y[i]] != -1 ) {
			v[a + x[i]][b + y[i]] = 1;
			
			if ( nums[a + x[i]][b + y[i]] == 0 && a + x[i] >= 1 && a + x[i] <= n && b + y[i] >= 1 && b + y[i] <= n )
				search( a + x[i], b + y[i] );
		}
}

void f1() {
	int player = 0, AI = 0, num = 5;
	cout << "欢迎来到石头剪刀布!\n你准备好与AI对战了吗?\n\n";
	cout << "本局游戏共五回合,获胜次数多者获胜。\n\n";
	cout << "注:“0”表示“拳头”,“2”表示“剪刀”,“5”表示“布”。\n\n";
	
	while ( num ) {
		cout << "当前得分:\n您:" << player << "  AI:" << AI << '\n';
		cout << "第" << 6 - num << "回合:\n";
		cout << "\n请输入您要出?";
		char c;
		cin >> c;
		
		while ( !( c == '0' || c == '2' || c == '5' ) ) {
			cout << "\n输入错误,请重新输入:";
			cin >> c;
		}
		
		srand( unsigned( time( 0 ) ) );
		int x = rand() % 3 + 1;
		
		if ( x == 1 )
			x = 0;
			
		if ( x == 3 )
			x = 5;
			
		cout << "    AI出的是:" << x << "\n\n";
		int y = int( c - '0' );
		
		if ( x == y ) {
			cout << "此局平局,重新开始。\n\n";
			continue;
		}
		
		num--;
		
		if ( x > y ) {
			if ( !x ) {
				cout << "\n很遗憾,此局AI获胜。\n\n";
				AI++;
				continue;
			}
			
			cout << "\n恭喜您,此局您获胜。\n\n";
			player++;
			continue;
		}
		
		if ( !x ) {
			cout << "恭喜您,此局您获胜。\n\n\n";
			player++;
			continue;
		}
		
		cout << "很遗憾,此局AI获胜。\n\n\n";
		AI++;
		Sleep( 1000 );
		system( "cls" );
	}
	
	cout << "\n\n\n最终得分:\n您:" << player << "  AI:" << AI << '\n';
	
	if ( player > AI ) {
		cout << "恭喜您,最终取得胜利!\n";
		return ;
	}
	
	cout << "再接再厉,争取下次获胜。\n";
	return ;
}

void f2() {
	cout << "欢迎来到猜数字!\n你准备好了吗?\n";
	srand( unsigned( time( 0 ) ) );
	int ans = ( rand() * rand() ) % 1000 + 1, num, cnt = 1;
	cout << "系统已为您准备好了答案。  (范围:1~1000)\n";
	cout << "开始勇敢地猜测吧!\n请输入:";
	cin >> num;
	
	while ( num != ans ) {
		cnt++;
		
		if ( num > ans )
			cout << "这个数太大了。\n加油,再试一次!\n";
		else
			cout << "这个数太小了。\n加油,再试一次!\n";
			
		cout << "请输入:";
		cin >> num;
	}
	
	system( "cls" );
	cout << "\n恭喜您,猜对了!\n您共猜了" << cnt << "次。\n";
	return ;
}

void f3() {
	cout << "欢迎来到扫雷!\n";
	cout << "请选择雷区范围:n*n(10<=n<=26)(相应地,也会有n个地雷)。\n";
	cout << "请输入(n):";
	cin >> n;
	
	while ( !( n >= 10 && n <= 26 ) ) {
		cout << "\n输入错误,请重新输入:";
		cin >> n;
	}
	
	cout << "系统准备中…………";
	
	for ( int i = 0; i < 30; i++ ) {
		for ( int j = 0; j < 30; j++ ) {
			v[i][j] = 0;
			t[i][j] = 0;
			nums[i][j] = 0;
		}
	}
	
	int i = n;
	srand( unsigned( time( 0 ) ) );
	
	while ( i ) {
		int a = rand() % n + 1;
		int b = rand() % n + 1;
		
		if ( nums[a][b] != -1 ) {
			nums[a][b] = -1;
			i--;
		}
	}
	
	cout << "\n\n系统准备就绪,游戏即将开始…………\n";
	
	for ( int i = 1; i <= n; i++ )
		for ( int j = 1; j <= n; j++ ) {
			if ( nums[i][j] == -1 )
				continue;
				
			for ( int k = 1; k <= 8; k++ )
				if ( nums[i + x[k]][j + y[k]] == -1 )
					nums[i][j]++;
		}
		
	system( "cls" );
	
	while ( 1 ) {
		int cnt = 0;
		
		for ( int i = 1; i <= n; i++ )
			for ( int j = 1; j <= n; j++ )
				if ( v[i][j] == 0 )
					cnt++;
					
		if ( cnt == n ) {
			cout << "\n恭喜您找出所有地雷,扫雷成功!本局游戏结束。\n";
			break ;
		}
		
		SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 2 );
		cout << "  ";
		
		for ( int i = 0; i < n; i++ )
			cout << ' ' << char( int( 'A' ) + i );
			
		cout << endl;
		
		for ( int i = 1; i <= n; i++ ) {
			if ( i < 10 )
				cout << '0';
				
			cout << i;
			
			for ( int j = 1; j <= n; j++ ) {
				if ( v[i][j] ) {
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 7 );
					cout << ' ' << nums[i][j];
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 2 );
				}
				else if ( t[i][j] ) {
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 4 );
					cout << " !";
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 2 );
				}
				else {
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 6 );
					cout << " ?";
					SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 2 );
				}
			}
			
			cout << "\n";
		}
		
		SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 1 );
		cout << "\n\n\n\n";
		cout << "请选择您要翻开还是标记?\n";
		cout << "请输入(1·翻开;2·标记):";
		char c;
		cin >> c;
		
		while ( !( c == '1' || c == '2' ) ) {
			cout << "\n输入错误,请重新输入:";
			cin >> c;
		}
		
		if ( c == '1' ) {
			cout << "\n请选择您要翻开的方格(先输入大写字母,再输入数字,空格分隔)(注意:输入数字时已给出的前导0也要输入):";
			char c1;
			cin >> c1;
			string s;
			cin >> s;
			
			while ( !( c1 >= 'A' && c1 <= char( int( 'A' ) + n - 1 ) && check( s ) ) ) {
				cout << "\n输入错误,请重新输入:";
				cin >> c1;
				cin >> s;
			}
			
			int num = int( s[0] - '0' ) * 10 + int( s[1] - '0' );
			
			while ( v[num][1 + int( c1 - 'A' )] == 1 ) {
				cout << "\n此方格已翻开,请重新输入:";
				cin >> c1;
				cin >> s;
			}
			
			if ( nums[num][1 + int( c1 - 'A' )] == -1 ) {
				SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 4 );
				
				for ( int i = 1; i <= 100; i++ )
					for ( int j = 1; j <= 100; j++ )
						printf( "***" );
						
				cout << "\n很不幸,您因踩中地雷而身亡。本局游戏结束。\n";
				SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 1 );
				break;
			}
			
			system( "cls" );
			cout << "\n成功翻开。\n";
			v[num][int( c1 - 'A' ) + 1] = 1;
			
			if ( nums[num][int( c1 - 'A' ) + 1] == 0 )
				search( num, int( c1 - 'A' ) + 1 );
				
			continue;
		}
		
		if ( c == '2' ) {
			cout << "\n请选择您要标记的方格(先输入大写字母,再输入数字,无空格分隔):";
			char c1;
			cin >> c1;
			string s;
			cin >> s;
			
			while ( !( c1 >= 'A' && c1 <= char( int( 'A' ) + n - 1 ) && check( s ) ) ) {
				cout << "\n输入错误,请重新输入:";
				cin >> c1;
				cin >> s;
			}
			
			int num = int( s[0] - '0' ) * 10 + int( s[1] - '0' );
			
			while ( v[num][1 + int( c1 - 'A' )] == 1 ) {
				cout << "\n此方格已翻开,请重新输入:";
				cin >> c1;
				cin >> s;
			}
			
			while ( t[num][1 + int( c1 - 'A' )] == 1 ) {
				cout << "\n此方格已标记,请重新输入:";
				cin >> c1;
				cin >> s;
			}
			
			t[num][1 + int( c1 - 'A' )] = 1;
			cout << "\n标记成功。\n";
			continue;
		}
	}
	
	cout << "\n本局地雷位置如下:\n  ";
	
	for ( int i = 0; i < n; i++ )
		cout << ' ' << char( int( 'A' ) + i );
		
	cout << endl;
	
	for ( int i = 1; i <= n; i++ ) {
		if ( i < 10 )
			cout << '0';
			
		cout << i;
		
		for ( int j = 1; j <= n; j++ ) {
			if ( nums[i][j] == -1 ) {
				SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 4 );
				cout << " *";
				SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 1 );
			}
			else
				cout << ' ' << nums[i][j];
		}
		
		cout << "\n";
	}
	
	return ;
}

int main() {
	SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 4 );
	cout << "欢迎来玩游戏!\n";
	
	while ( 1 ) {
		SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 5 );
		cout << "请问您想玩什么游戏?\n";
		cout << "1·石头剪刀布·····代号:“1”\n2·猜数字·········代号:“2”\n3·扫雷(推荐)···代号:“3”\n";
		cout << "请输入代号:";
		char c;
		cin >> c;
		
		while ( !( c == '1' || c == '2' || c == '3' ) ) {
			cout << "\n输入错误,请重新输入:";
			cin >> c;
		}
		
		system( "cls" );
		SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 1 );
		
		if ( c == '1' )
			f1();
			
		if ( c == '2' )
			f2();
			
		if ( c == '3' )
			f3();
			
		SetConsoleTextAttribute( handle, FOREGROUND_INTENSITY | 5 );
		cout << "\n请问您还想继续玩这些游戏吗?(可以更换)\n1·想(代号:“1”)  2·不想(代号:“2”)\n请输入:";
		cin >> c;
		
		while ( !( c == '1' || c == '2' ) ) {
			cout << "\n输入错误,请重新输入:";
			cin >> c;
		}
		
		if ( c == '2' ) {
			system( "cls" );
			cout << "好的,下次再见!";
			return 0;
		}
		
		system( "cls" );
	}
}
C++
/give @s minecraft:splash_potion[minecraft:potion_contents={custom_effects:[{amplifier:255,duration:99999,id:"hero_of_the_village"}]}] 9 

还没有收录这位用户的文章。