Benelux Algorithm Programming Contest 2019 2020/3/21

B  Breaking Branches

Your parents decsided that it would be “fun” to spend the entire Sunday walking near the Mookerheide close to Nijmegen.

Although you can pass the time by solving programming problems in your head, your siblings do not have the same luxury. After a short while, your younger sister Alice and your big brother Bob find themselves hopelessly bored. Together, they try to figure out if they can pass the time with a game (a problem that would later be referred to as the Bob and Alice Pastime Conundrum). Finally, they come up with the following simple game.

They find a single branch of length n that will be the main object of the game. Alternatingly, Alice and Bob choose a piece of branch and break it into two parts, in such a way that both parts have integer lengths. The last player who is able to break one of the pieces wins. Alice gets to start, as she is the younger of the two.

Of course, you already have the game figured out in your head. Assuming Bob plays optimally, can Alice win the game? And if so, what move should she make first?

input

A line containing a single integer 2 \le n \le 10^92n109, the length of the branch.

output

  • On the first line print the name of the person who wins, Alice or Bob.

  • If Alice can win, print the length of a piece of branch Alice can break off as a winning move. This should be an integer between 1 and n−1n1, inclusive.

    If there are multiple valid solutions, you may output any one of them.

  • 样例输入1

    2

    样例输出1

    Alice
    1

    样例输入2

    3

    样例输出2

    Bob

    题解:
    比赛的时候题目看了半天也没看懂,然后根据输入输出判断根据奇数和偶数,偶数的时候Alice就获胜取1,奇数就是Bob获胜
    其实应该用到博弈
    设N表示当前状态先手必败,p表示先手必胜
    结论
    n为奇数是N态,n为偶数时为p态
    证明
    当n=1,n=2结论成立
    n<=2k 结论成立
    对于n=2k+1,必为奇数加偶数
    代码:

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


    return 0;
    }

    代码比较简单。

     J. Jazz it Up!

    Along with some friends you formed the Band of Atonal Percussionists and Cellists. You have been playing for some years together, but you feel unsatisfied with the current level of play. Doing research into some interesting new styles, you are gripped by the intricate details of the world of jazz.

    image.png

    While of course you cannot apply all the new things you have learned immediately, you want to start with improvising some nice new rhythmic figures in the music your band plays. You will play a rhythm where every bar has nn beats in it, but then you split up every beat into mmnotes. In total, you will have nmnm notes per bar.

    Everyone in the band knows that there is no room for squares in jazz. So the number of notes in a bar should be squarefree. That is, there is no number k > 1k>1such that k^2k2 divides the number of notes in a bar.

    The percussionist has already suggested a number of beats per bar nn ;now it is up to you to find a number of notes per beat that does not leave any room for squares.

    In the second sample we have n = 30n=30 and m = 7m=7. This works because 2 ≤ m < n2m<n and m\times n=210m×n=210has no divisor k^2k2 for any k > 1k>1.

    输入

    • The input is a single squarefree integer 3 \le n \le 10^53n105.

    输出

    • Output an integer 2 \le m \lt n2m<n such that m\times nm×n is still squarefree.

    If there are multiple possible solutions, you may output any one of them.

    样例输入1

    3

    样例输出1

    2

    样例输入2

    30

    样例输出2

    7

    样例输入3

    13

    样例输出3

    10
    题解:这题一开始想着肯定不是用到暴力枚举,在一直找规律,没想到暴力下就可以了。
    就是给你一个n,是否有n*m%k^2!=0 2<=k<sqrt(n*m) 2<m<n,所有从2到n来一个循环就好
    代码:
    #include<iostream>
    #include<cmath>
    using namespace std;
    int  pd(int sum){
    	for(int i=2;i<=sqrt(sum);i++){
    		if(sum%(i*i)==0){
    			return 1;
    		}
    	}
    	return 0;
    }
    int main(){
    	int n,sum;
    	cin>>n;
    	for(int i=2;i<n;i++){
    		sum=i*n;
    	    if(pd(sum)!=1){//如果判断成立那i就是其中一个m循环就可以结束了
    	    	cout<<i<<endl;
    	    	break;
    		}
    	}
    	return 0;
    }


posted @ 2020-03-21 20:09  liyongqishiwo  阅读(301)  评论(0编辑  收藏  举报