听说是微软面试题 (0分)

5,6绝对不正确:
如果大家算过的话,能让甲说出第一句话只有两个可能:x+y=11和x+y=17(至于怎么得到的说来话长,但是不难)
假设乙的数是30,30可以分解成2*15,3*10,5*6
这里面2+15=17,5+6=11这样,乙连第2句话都说不出来
 
不是数学问题。
何来算去算来?!
 
高手给个DELPHI的算法了[8D]
 
题目不对,少了一句,
要是这样的话是无解了。
 
据说这是正解!!!!!!!!!!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1921982
 
没错,前面是我想的不周到。
甲说:“我不知道X和Y是多少,但你也不知道”
这句话表示,不是两个质数,因为如果是2个质数,那么乙肯定知道。
但甲只知道两数的和,怎么知道不是两个质数呢?肯定是和的所有分解都不会是两个质数相加。
由此可得到和的集合。
乙说:“我知道X和Y分别是多少了!”
甲说:“我也知道了”
表示所有相加组合中,两数的积的所有分解,的和,只有1个是在和的集合中。
下面是算法:(一个上午啊…………)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
function IsZhi(a: integer): BOOLEAN;
function Check2(a: integer): BOOLEAN;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: integer;
k:boolean;
begin
memo1.Lines.Clear;
for i := 6 to 60do
begin
for j := 2 to i div 2do
begin
if not IsZhi(j) then
begin
k := true;
continue;
end
else
if IsZhi(i - j) then
begin
k := false;
break;
end;
end;
if k then
memo1.Lines.Add(inttostr(i));
end;
Button2Click(nil);

end;

function TForm1.IsZhi(a: integer): BOOLEAN;
var
i: integer;
begin
result := true;
for i := 2 to a - 1do
if (a mod i) = 0 then
begin
result := false;
Exit;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i, j, n, m, x, y: Integer;
begin
for i := 0 to memo1.Lines.Count - 1do
begin
n := StrToInt(memo1.Lines.Strings);
m := 0;
for j := 2 to n div 2do
begin
if Check2(j * (n - j)) then
begin
m := m + 1;
x := j;
y := n - j;
end;
end;
if m = 1 then
begin
showmessage(inttostr(x)+' -- '+inttostr(y));
Exit;
end;
end;
end;

function TForm1.Check2(a: integer): BOOLEAN;
var
i, n, m: Integer;
begin
result := false;
n := 0;
m := 0;
for i := 2 to a div 2 - 1do
begin
if a mod i <> 0 then
Continue
else
if (memo1.Lines.IndexOf(IntToStr(i + (a div i))) <> -1) and (i <> m) then
begin
m := a div i;
n := n + 1;
end;
end;
if n = 1 then
result := true;

end;

end.
 
只要甲或乙有一方知道答案,这个问题就解决了。
我认为微软不是要的结果,而是看你思维的方式。
 
不要陷入找答案的陷阱中。
甲乙任何一方知道就是已知数了~
 
整一个脑筋急转弯:
乙已经知道了X*Y的结果,那甲肯定知道X+Y的结果了饿!哈...
 
如果是微软面食题目
它的另类解乏是
不一定要做出来
关键是通过
 
当然可以有解,这个题目早讨论过了,而且是100以内的,找一下以前的题目就知道了。
 
题目似乎有问题:
甲怎么可能知道乙知不知道呢??
 
觉得Xelloss想法不错,应该是对的,从素数的角度可以找出答案
不过我想这个要对数字非常敏感吧,不然面试那么短的时间内想出来也太强了吧
 
x=27
y=28
这种情况好象可以
 
Xelloss 的是正解应该
至于Microsoft的考试,我想如果你能够有这个思路,那么这道题肯定就通过了
 
基本上明白,佩服孙哥,庞哥如此电算。
继续佩服中。我的脑袋为什么就没那么快呢。
 
Xelloss
但为什么乙会知道X和Y是多少呢???
 
是2和29吧!
大家先考虑一下,觉得可能顶一下,在出算法!
 
顶部