zerojudge d063. 0 與 1

zerojudge d063. 0 與 1


題意:若輸入0輸出1,若輸入1輸出0


解法大全:

判斷式:

三元運算子


布林代數:!

n=!n;

n= not n;


n=n^1 (n^=1)

n= n xor 1


布林代數比較:

n=(n!=1)

n=(n==0);

n=(n<1);


式子:

求經過(1,0)和(0,1)的點


ans:

1)y=-(x-1);

2)y=(x-1)*(x-1);

3)y=| x-1|;


[process and proof]

1)Let it be a linear equation(y=mx+b)

replace the points (0,1) and (1,0).

0=1*m+b;

1=0*m+b;

get m=-1,b=1;

2)Let it be a quadratic equation(y=a*x*x+b*x+c)

replace the points (0,1) and (1,0).

1=a*0+b*0+c;

0=a*1+b*1+c;

get c=1; which has infinitely many solution.(a*x*x-b*x=-1)

the euation can be simplify y=(x-1)*(x-1); if a=1,b=-2;

3)according to 1),2)

we can conclude that y=|x-1|;

#end

Comments

Popular posts from this blog

zerojudge c561. Bert 愛搗蛋

zerojudge d122. Oh! My Zero!!