首页 新闻 会员 周边 捐助

大牛请进,POJ难题

0
悬赏园豆:100 [待解决问题]

那天在poj上随便翻了个题目来做,发现运气太差,遇到个难题,而且网上没有相关资料,

白白消耗了一整天的脑细泡,好失落,希望有大牛帮忙指点!

poj1900

原题如下:

Description

There is a legend that mathematicians in the XVIII century enjoyed playing the following game. 

The game was played by three mathematicians. One of them was the game master. First of all, the game master declared some positive integer number N . After that he chose two different integer numbers X and Y ranging from 1 to N and told their sum to one player and their product to the other player. Each player knew whether he was told the sum or the product of the chosen numbers. 

After that the players in turn informed the game master whether they knew the numbers he had chosen. First the player who was told the sum said whether he knew the numbers, after that the player who was told the product did, and so on. 

For example the dialog could look like this: 

Game master: "Let N be 10". 

After that he chooses two numbers ranging from 1 to 10 and tells their sum to player S and their product to player P. 

Player S: "I don't know these numbers." 

Player P: "I don't know these numbers." 

Player S: "I don't know these numbers." 

Player P: "I don't know these numbers." 

Player S: "Oh, now I know these numbers. You have chosen 3 and 6." 

Given N and M -- the number of times the players have said "I don't know these numbers", you have to find all possible pairs of numbers that could have been chosen by the game master. 

Input

The first line of the input contains N and M (2 <= N <= 200, 0 <= M <= 100).

Output

First output number of possible pairs of numbers that could have been chosen by the game master from the range 1 to N if both players altogether had said "I don't know these numbers" M times. After that output these pairs in arbitrary order, one on a line. 

Sample Input

10 4

Sample Output

3
2 5
3 6
3 10

嗯,希望大牛帮忙指点,越详细越好!
asonga的主页 asonga | 初学一级 | 园豆:93
提问于:2014-08-15 17:31
< >
分享
所有回答(2)
0

如果你翻译成中文的话,我还真有兴趣给你看看```

吴瑞祥 | 园豆:29449 (高人七级) | 2014-08-15 18:30

难得你感兴趣,

题意大概为:三个数学家玩游戏,其中一个为master,另外两个位S,P;master给定他们两一个整数N,然后再选定范围在1-N的两个数,告诉S 这两个数的和,再告诉P这两个数的积,S,P知道自己被告知的是和还是积,接下来,S和P分别告诉master,S:我不知道原两个数;P:我不知道原两个数。。。。经过M句,然后S或者P便知道了答案:告诉master:我知道答案了:为xx;

现在要做的是:给定N和M,求接下来的S或者P所知道的所有可能的答案;

比如:

输入  10  4

输出   3

  2 5

  3 6

  3 10

支持(0) 反对(0) asonga | 园豆:93 (初学一级) | 2014-08-16 10:35
0

这题你看懂了吗,我咋连题都没看懂呢,告诉S9,告诉P18,为啥两轮不知道之后S就知道是3 6了?

琴剑飘零 | 园豆:419 (菜鸟二级) | 2014-08-16 11:54

嗯,我只懂了一点点,但是不会求,比如,告诉S是9,告诉P是14,S开始肯定不知道,P第一轮就知道了,只有2*7=14,然后S得知P知道后,S也知道了,因为9=1+8,1*8=2*4不唯一,9=2+7,2*7=14唯一即答案,9=3+6,3*6=2*9不唯一,9=4+5,4*5=2*10不唯一,不知道你明白了没。我只是举个简单的例子,这个比较简单的,一轮就出来了,如果难的几轮,甚至几十轮,那肯定得用算法了,题目也说了,是几个数学家玩的游戏,我们头脑没他们好,所以得用计算机来实现~~~~~

支持(0) 反对(0) asonga | 园豆:93 (初学一级) | 2014-08-16 12:00

@asonga: 哎,十分sorry,当天就放弃了~

支持(0) 反对(0) 琴剑飘零 | 园豆:419 (菜鸟二级) | 2014-08-18 17:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册