第14章 博弈论基础(《C++编程与信息学竞赛数学基础》)

1、T557802 062-14-C01-取硬币游戏

https://www.luogu.com.cn/problem/T557802

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    while(cin>>n&&n!=0) {
        if(n<=2) cout<<"Alice"<<endl;
		else cout<<"Bob"<<endl;
    }
    return 0;
}



2、T553290 06-14-C02-遥控机器人

https://www.luogu.com.cn/problem/T553290

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int solve(){
	ll d,k,n,x,y;
	cin>>d>>k;
	n=d/(sqrt(2)*k);
	x=(n+1)*k;
	y=n*k;
	if(x*x+y*y>d*d){
		cout<<"Bob"<<'\n';
	}else{
		cout<<"Alice"<<'\n';
	}
	return 0;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



3、T553291 06-14-C03-欧几里德游戏

https://www.luogu.com.cn/problem/T553291

#include <bits/stdc++.h>
using namespace std;
bool f(int x,int y){
	if(x<y){
		swap(x,y);
	}
	if(x%y==0){
		return 1;
	}
	if(x<2*y){
		return !f(x-y,y);
	}
	return 1;
}
int main()
{
	int x,y;
	cin>>x>>y;
	if(f(x,y)){
		cout<<"Alice wins";
	}else{
		cout<<"Bob wins";
	}
	return 0;
}



4、T553292 06-14-C04-Nim取石头游戏

https://www.luogu.com.cn/problem/T553292

#include <bits/stdc++.h>
using namespace std;
int n,a[105],t;
int main()
{
	int i,j;
	cin>>n;
	cin>>a[1];
	t=a[1];
	for(int i=2;i<=n;i++){
		cin>>a[i];
		t^=a[i];
	}
	if(t==0){
		cout<<"B wins";
		return 0; 
	}
	
	cout<<"A wins"<<'\n';
	int k=31;
	while(!(t&1<<k)){
		k--;
	}
	for(int i=1;i<=n;i++){
		if(a[i]&1<<k){
			j=i;
			break;
		}
	}
	cout<<j<<" "<<a[j]-(a[j]^t)<<'\n';
	return 0;
}

5、T553293 06-14-C05-改数游戏

https://www.luogu.com.cn/problem/T553293

#include <bits/stdc++.h>
using namespace std;
long long n,a[100],b[100],t;
int main()
{
	int i,j,x=0;
	cin>>n;
	while(n)
	{
		b[++x]=n%10;
		n/=10;
	}
	for(i=1;i<=x;i++){
		t^=b[i];
	}
	if(t==0){
		cout<<"B wins";
		return 0; 
	}
	cout<<"A wins"<<'\n';
	int k=6;
	while(!(t&1<<k)){
		k--;
	}
	for(i=1;i<=x;i++){
		if(b[i]&1<<k){
			j=i;
			break;
		}
	}
	cout<<j<<" "<<(b[j]^t)<<'\n';
	return 0;
}



6、T557803 062-14-D01-Nim取石头游戏(2)

https://www.luogu.com.cn/problem/T557803

#include <bits/stdc++.h>
using namespace std;

void solve(int n)
{
	int a[105],t;
	int i,j;
	cin>>a[1];
	t=a[1];
	for(int i=2;i<=n;i++){
		cin>>a[i];
		t^=a[i];
	}
	if(t==0){
		cout<<"0"<<'\n';
		return; 
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if((a[i]^t)<a[i]){
			ans++;
		}
	}
	cout<<ans<<'\n';
	return;
}
int main()
{
	int n;
	while(cin>>n){
		if(n==0)break;
		solve(n);
	}
}






【数学基础】03-初等几何

https://www.luogu.com.cn/training/675204#problems

https://blog.csdn.net/dllglvzhenfeng/article/details/156864234

第8章 组合数学《C++编程与信息学竞赛数学基础》

https://blog.csdn.net/dllglvzhenfeng/article/details/156614120




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值