Wannafly Challenge 23 (SG function)

Links: https://www.nowcoder.com/acm/contest/161/B
Source: Cattle-off network
 

Title Description

N and O in a small little play games. N front of them put a heap of stones, the i-heap of stones started with a ci marbles. They took turns taking stones from a heap of stones, can not take. Finally, people can not operate to lose this game. But they think it is too boring to play, update the rules a little. Particularly is this: for a pile of stones there are exactly m pieces heap of stones, stones if taken from a person in this pile of stones, provided he is to take the number of stones d, then d must be a divisor of m. Finally, the operator still can not lose.
Now small N upper hand. He wanted to know how many different he was the first step of a winning strategy. A strategy means that heap from which stones, the number of stars stones removed. As long as that takes a bunch of different, different numbers or take, they are considered different strategies.

Enter a description:

A first line integer n. 
The next line n integers, representing the number of each pile gravel stones. 
Ensure that the input data of all numbers are not more than 105, greater than or equal to 1 and is an integer.

Output Description:

A row of small $ N $ integer representing the number of the first step in winning strategy.

Example 1

Entry

copy

10
47 18 9 36 10 1 13 19 29 1

Export

copy

7

Obviously is a bare board will not engage in the question himself, obviously seen many times more than the school factors play table, life and death with no success factor of 1e5 table.

	//因子表打法
    for(int i=1;i<=n;i++)
	for(int j=1;j*i<=n;j++)
	{
		q[i*j].push_back(i);
	}

This time we must remember these three lines of code.

Then you can play out sg function of the table 1-100000. sg function can not understand poke   https://mp.csdn.net/postedit/81512877

After the meeting the SG function poj2975 this question you will be up. Zhetijiuhuo poj2975 the like. Every time we subtract a number of factors, and then the rest of the judgment under XOR value is not 0 can be. After taking the upper hand factor, SG if the remaining number is 0, then flip doomed to failure. Another point to note XOR operator precedence low, remember parentheses.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100001

int f[N],sg[N],has[N];     
vector<int> q[100005];
void getSG(int n)
{
	for(int i=1;i<=n;i++)
	for(int j=1;j*i<=n;j++)
	{
		q[i*j].push_back(i);
	}
    memset(sg,0,sizeof(sg));
    for(int i=1;i<=n;i++)
    {
    	int len=q[i].size();
        for(int j=0;j<len;j++)
            has[sg[i-q[i][j]]]=1;
        for(int j=0;j<=n;j++)
        {
            if(has[j]==0)
            {
                sg[i]=j;
                break;
            }
        }
        for(int j=0;j<len;j++)
            has[sg[i-q[i][j]]]=0;
    }
}
int a[100005];
int main()
{	
	int n;
	
	getSG(100000);
	scanf("%d",&n);
	
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;a[i]=x;
		ans^=sg[x];
	}
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<q[a[i]].size();j++)
		if((sg[a[i]-q[a[i]][j]]^(ans^sg[a[i]]))==0) sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

 

Published 155 original articles · won praise 32 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_37632935/article/details/82262801
sg