hdu 1030 数学题加观察

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector>

using namespace std;
#define INF 0x7fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
#define MAXN  1000000000
LL n,m;
int main(){
	int t = 0;
	while(cin >> n >> m){
		if(n>m)
			swap(n,m);
		int cenn  =ceil(sqrt(n));
		int cenm = ceil(sqrt(m));
		int lev = cenm - cenn;
		int lef = abs( (cenm -( m - (cenm-1)*(cenm-1))/2)- (cenn - (n- (cenn-1)*(cenn-1))/2));
		int righ =abs(cenm-(cenm*cenm-m+1)/2-(cenn-(cenn*cenn-n+1)/2));
		cout << lev + lef + righ << endl;
	}
	return 0;
}

//其实这个最短路径的本质是最少经过多少水平边+左斜边+右斜边

只要求出以水平为基准的层数,左斜边的为基准的层数,右斜边为基准的层数然后互相减去就是答案了

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-29 18:26:39

hdu 1030 数学题加观察的相关文章

HDU 1030 数学题

给出两点,求这两点在图上的最短路径 分别以最上,左下,右下为顶点,看这个三角图形 ans=这三种情况下两点的层数差 #include "stdio.h" #include "string.h" #include "math.h" int main() { int n,m,sn,sm,rn,rm,ln,lm,ans; while (scanf("%d%d",&n,&m)!=EOF) { sn=sqrt(n); i

hdu 1030

Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5611    Accepted Submission(s): 2137 Problem Description A triangle field is numbered with successive integers in the way shown on the

hdu 4004 (二分加贪心) 青蛙过河

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂直于河岸的一条直线上) 还有青蛙能够跳跃的 最多 的次数,还有每个石头离河岸的距离,问的是青蛙一步最少要跳多少米可以过河> 这是一道二分加贪心的题,从0到的河宽度开始二分,二分出一个数然后判断在这样的最小步数(一步跳多少距离)下能否过河 判断的时候要贪心 主要难在思维上,关键是要想到二分上去,能想到

HDU 5073 数学题

题目传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5073 这道题RE了好多发啊囧,RE到精神不振. Galaxy的质心并不是一成不变的,随着一些星球的移动而变化,最终质心就变成了坐标和的平均值了. 具体思路如右http://mathlover.info/archives/hdu5073 代码就补贴了囧...

HDU 5652 二分加搜索 http://acm.split.hdu.edu.cn/showproblem.php?pid=5652

Problem Description A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise up. With that at first the communation started to reduce a

hdu 6288(二分法加精度处理问题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6288 题意:给出a,b,k,n可满足(n^a)*(⌈log2n⌉)^b<=k ,求最大的n值三个正整数a,b,k(1≤a,b≤10,10^6≤k≤10^18) 题目思路:这类给数学式子求n的最大值,且数据量大且多的,考虑时间复杂度,我们采用二分法找出n 思路:很明显就是二分n,向上取整可以先预处理出2^62,然后直接循环找到b的底数j,处理n^a*j^b一开始我们用的是powl,但是被卡精度了,卡了

hdu 1030 Delta-wave

Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8166    Accepted Submission(s): 3219 Problem Description A triangle field is numbered with successive integers in the way shown on the

hdu 5065 数学题

#include<iostream> #include<cmath> #include<cstdio> using namespace std; int A,B,y; double ans=0; double inline f(double x) { return A*x*x-(B*sin(x)+y); } double inline absf(double x) { if(f(x)<0)return -f(x); return f(x); } bool find

hdu 3591 多重加完全DP

题目: The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1997    Accepted Submission(s): 711 Problem Description In the country of ALPC , Xiaoqian is a very famous mathematici