取石子游戏

GitHub跳转原题关系图返回列表

题意与原解析均从本地 OpenJudge 缓存迁移。

OJ: noi_openjudge

题目 ID: ch0205-6266

难度:未知

标签:

日期: 2026-07-30 23:01

题意

完整题面见同目录的 problem.md

思路

代码

cpp
#include <cstdio>
#include <iostream>
using namespace std;


void swap(int &x,int &y){
	int t= x;
	x =y;
	y =t;
}

//
bool dfs(int t1,int t2){
	if(t1 < t2) swap(t1,t2);
	if( t1 % t2 == 0 || t1 / t2 >=2) 
		return true;
	return !dfs(t1-t2,t2);
}


int main(){
	int x,y;
	
	while(1){
		cin >> x >> y;
		if( x== 0 && y== 0)
			break;
		if( dfs(x,y))
			cout << "win" << endl;
		else
			cout << "lose" << endl;
	}
	
	return 0;
}

复杂度

总结