【CCF历年题题解】201712-2 游戏【模拟】

虽然样例过了,但是第一次交上去只有10分,原因是person越界了。
考试时还是要自己多生成样例测试!,一锤子买卖!

#include <iostream>

using namespace std;

const int N = 1010;

int n,k;
bool st[N];

bool check(int x)
{
    
    
	if( (x % k == 0) || (x % 10 == k)) return true;
	return false;
}

int main()
{
    
    
	cin >> n >> k;
	//cout << n <<" " << k <<endl;
	int cnt = n;
		
	int num = 1;
	int person = 1;
	
//	if(k == 1) cout << n ;
//	else
	{
    
    
		while(cnt > 1)
		{
    
    
			if(person > n) person = 1; // 连续的continue,person越界,调试的时候要打印出来看看 
			if(st[person]){
    
    
				person ++;
				continue;
			}
			
			//cout <<person <<" 报号->"<< num <<endl;
			if(check(num))
			{
    
    
				st[person] = true;
				//cout << person <<"小朋友出局了" <<endl;
				cnt --;
			}
			
			person ++ ;
			num ++;
			if(person > n) person = 1;
		}
		
		for(int i=1;i<=n;i++)
			if(!st[i]) cout << i <<endl;
	}
		
	
	return 0;

}

猜你喜欢

转载自blog.csdn.net/weixin_43154149/article/details/108524969