锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
涓涓幆褰㈢殑鍦堟庢牱鐢ㄦ渶灝戞鏁版妸瀹冧粠欏烘椂閽堝彉鎴愰嗘椂閽堬紙鍙兘鐩擱偦浣嶇疆浜ゆ崲浣嶇疆錛?br>涓涓幆褰紝鏈浼樼粨鏋滄槸鎶婅繖涓幆鍒嗘垚 鐩稿樊 鏈灝戠殑2閮ㄥ垎錛岃繖2閮ㄥ垎鎸夌収鐩寸嚎鏉ユ眰鍑虹粨鏋滃啀姹傚拰
鐩寸嚎濡傛灉鎶?234 鎹㈡垚4321
鏄啋娉$殑嬈℃暟銆傘傞鍏?123錛?錛?4312錛?錛?4321錛?錛?6
鏈鏄妸n鐪嬫垚涓や釜 n/2 錛岀劧鍚庢眰鍑鴻繘琛屽弽搴忥紙鍐掓場錛夌殑嬈℃暟
int main()
{
int n,t,r;
while(scanf("%d",&n)!=EOF)
{
t=n/2; r=n-t;
printf("%d\n",t*(t-1)/2+r*(r-1)/2);
}
return 0;
}
]]>

The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route.
Write the program to determine the length of the shortest route connecting cells with numbers N and M.
#include <stdio.h>
#include<math.h>
int main()

{
int temp,n,m,s,flag=3,cn,cm,zb,yb,cc,k,sj;
while(scanf("%d%d",&m,&n)==2 )
{
flag=3; s=0; k=0;
if(m>n) 
{
temp=m; m=n; n=temp;
}
cn=(int)ceil(sqrt(n)); //鍒ゆ柇n鍜宮鎵鍦ㄥ眰鏁?/span>
cm=(int)ceil(sqrt(m));
cc=abs(cn-cm); //鍒ゆ柇涓ょ偣灞傚樊
zb=m+(cn-1)*(cn-1)-(cm-1)*(cm-1); //鍒ゆ柇m杈愬皠鍒皀灞傛墍鍙婅寖鍥寸殑宸﹁竟鐣屽拰鍙寵竟鐣?/span>
yb=zb+2*cc;
if(n>=zb && n <=yb) //鍒ゆ柇n鍦╩鑼冨洿鎵欏繪鏁?/span>
{
s=2*(cc);
k=1;
}
else
{
if(n<zb) //鍒ゆ柇n鍒癿杈圭晫鍙妋鐐規墍欏繪鏁板拰
s=2*(cc)+abs(n-zb);
else
s=2*(cc)+abs(n-yb);
}
sj=m-(cm-1)*(cm-1); //鍒ゆ柇涓夎綾誨瀷0姝?1鍊?/span>
if(abs(n-m)% 2 !=(cc) % 2)
{
if(sj % 2 ==1 )
flag=1;
else
flag=0;
}
if(flag==1 && k==1)
s=s-1; //鍋囧n鐐瑰湪m鐐硅緪灝勮寖鍥村唴,姝d笁瑙?1,鍊掍笁瑙?1,涓嶅湪涓嶅垽鏂?
if(flag==0 && k==1)
s=s+1;
printf("%d\n",s);
}
return 0;
}
涓や釜鐩稿噺灝辨槸m琛岀殑涓暟浜嗭紒~ m鍔犱釜鏁頒笉灝辨槸宸﹁竟鐣屼簡鍢泘
zb+涓ゅ嶇殑琛屽樊灝辨槸鍙寵竟鐣屼簡錛亊
鑰屼笖姝d笁瑙掓墍鍒扮殑杈圭晫鏄涓夎鍨嬶紝鍙嶄笁瑙掓墍鍒扮殑杈圭晫鏄弽涓夎鍨嬶紝榪欑偣瑕佹敞鎰忥紒
]]>
#include<math.h>
int main()
{
int n,a;
scanf("%d",&n);
while(n--)
{
scanf("%d",&a);
printf("%d\n",(int)sqrt(a*1.0));
}
return 0;
}
]]>