麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

hdu1030【找規律】

2019-11-14 08:44:49
字體:
來源:轉載
供稿:網友

A triangle field is numbered with successive integers in the way shown on the picture below.

這里寫圖片描述

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.

Input Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).

Output Output should contain the length of the shortest route.

Sample Input 6 12

Sample Output 3

題解:找規律題,把整個三角形轉化成一個三維的坐標軸 這里寫圖片描述 例:對于6,在第三行,z=3, x=(9-6)/2+1=2, y=(6-4-1)/2+1=1,所以(2,1,3); 對于12,在第4行,z=4, x=(16-12)/2+1=3,y=(12-9-1)/2+1=2,所以(3,2,4); 兩個點的最短距離=x、y、z坐標差的絕對值

代碼:

#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#define MST(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 1005using namespace std;int x[1000005];int main(){ int n, m; while (cin >> n >> m) { int Za = (int)ceil(sqrt(n * 1.0)); int Zb = (int)ceil(sqrt(m * 1.0)); int Xa = (Za * Za - n) / 2 + 1; int Xb = (Zb * Zb - m) / 2 + 1; int Ya = (n - (Za - 1) * (Za - 1) - 1) / 2 + 1; int Yb = (m - (Zb - 1) * (Zb - 1) - 1) / 2 + 1; int ans = (int)( fabs((Za - Zb) * 1.0) + fabs((Xa - Xb) * 1.0) + fabs((Ya - Yb) * 1.0) ); printf("%d/n", ans ); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲第一页综合 | 国产在线观看91精品 | 国产v综合v亚洲欧美久久 | 成人毛片100部 | 久久精品视频一区二区三区 | 国产精品成年片在线观看, 激情小说另类 | 欧美a久久 | 日韩字幕在线观看 | 91成人天堂久久成人 | av噜噜在线 | 毛片视频免费观看 | 免费看真人a一级毛片 | 久久九九热re6这里有精品 | 一级免费在线视频 | 国产女厕一区二区三区在线视 | 国产成人高清成人av片在线看 | 国产99久久久久久免费看 | 精品亚洲视频在线 | 国产精品久久久久av | 久久久久北条麻妃免费看 | 日韩蜜桃视频 | 久久精品国产99国产精品澳门 | 亚洲第一成av人网站懂色 | 国产88久久久国产精品免费二区 | av免费av | 成人免费电影在线观看 | 国产又白又嫩又紧又爽18p | 国产精品视频在线观看免费 | 免费观看的毛片手机视频 | 免费视频www在线观看 | 日本欧美一区二区三区在线播 | 日韩黄色片在线观看 | 亚洲一区二区三区日本久久九 | 亚洲精品一区二区三区在线看 | 亚洲成人福利在线观看 | 在线成人免费观看视频 | 国产午夜精品在线 | 午夜视频久久 | 亚洲成人免费视频在线 | 在线成人免费网站 | 97精品国产高清在线看入口 |