HDUOJ----(1030)Delta-wave
Delta-wave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4684 Accepted Submission(s): 1777
 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.
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.
 比如6 16 向右移一格..经过两条边即可...然后将其分层,确定他们的行列来计算相应的值即可。。哎呀,说不清了..
比如6 16 向右移一格..经过两条边即可...然后将其分层,确定他们的行列来计算相应的值即可。。哎呀,说不清了..#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int sum(int m,int &cc)
{ int rr=(int)sqrt(1.0*m); //确定她所在第几行..一右边为参数
if(rr*rr!=m) rr++;
cc=rr*rr-m;
if(cc&)
return *(rr-);
else
return *rr-;
} int main()
{
int n,m,ncc,mcc,add;
while(cin>>m>>n)
{
int rankn=sum(n,ncc); //得到n的所在第几行
int rankm=sum(m,mcc); //得到m的所在第几行
ncc>>=; //得到n所在第几列,以右边为参数
mcc>>=; //得到m所在第几列,以右边为参数
//此处可以进一步优化...现在就不优化了..
if(rankn==rankm)
cout<<abs(n-m)<<endl;
else
if(rankn<rankm)
{ if(mcc>=ncc&&mcc<=(rankm-rankn)/+ncc)
cout<<(rankm-rankn)<<endl;
else
{ if(*mcc<(rankm-rankn)/+*ncc)
{
add=ncc-mcc;
cout<<*add+(rankm-rankn)<<endl;
}
else
{
add=mcc-((rankm-rankn)/+ncc);
cout<<*add+(rankm-rankn)<<endl;
} }
}
else
{
//rankn>rankm
if(ncc>=mcc&&ncc<=(rankn-rankm)/+mcc)
cout<<(rankn-rankm)<<endl;
else
{
if(*ncc<(rankn-rankm)/+*mcc)
{
add=mcc-ncc;
cout<<*add+(rankn-rankm)<<endl;
}
else
{
add=ncc-((rankn-rankm)/+mcc);
cout<<*add+rankn-rankm<<endl;
}
}
}
/* cout<<0&1<<endl;*/
} return ;
}
HDUOJ----(1030)Delta-wave的更多相关文章
- uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)
		option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ... 
- HDU3723 Delta Wave —— 卡特兰数
		题目链接:https://vjudge.net/problem/HDU-3723 Delta Wave Time Limit: 6000/3000 MS (Java/Others) Memory ... 
- HDU 3723 Delta Wave (高精度+calelan数)
		题意:给定一个图,问你只能向上向下,或者平着走,有多少种方法可以走到最后一个格. 析:首先先考虑,如果没有平的情况就是calelan数了,现在有平的情况,那么就枚举呗,因为数很大,所以要用高精度. 答 ... 
- RIFF和WAVE音频文件格式
		RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ... 
- BZOJ 1030: [JSOI2007]文本生成器 [AC自动机 DP]
		1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3953 Solved: 1614[Submit][Stat ... 
- IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)
		IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ... 
- Wave - 花たん 音乐
		Wave 歌手:花たん 所属专辑:Flower 間違えて宇宙終わって(宇宙因为一个错误而终结了) 青信号はいつも通り(通行的灯号一如往常的) 飛んでまた止まって(又再停止传播) また 飛びそうだ(然后 ... 
- Dirac Delta Function
		也称为Degenerate pdf, 退化概率密度函数. 未经考证的解释是: 当正态分布的\(\sigma \to 0\)时, 正态分布就退化为这个分布了. 定义 \[ \delta(x) = \be ... 
- PAT A 1030. Travel Plan (30)【最短路径】
		https://www.patest.cn/contests/pat-a-practise/1030 找最短路,如果有多条找最小消耗的,相当于找两次最短路,可以直接dfs,数据小不会超时. #incl ... 
- hduoj 1455 && uva 243 E - Sticks
		http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ... 
随机推荐
- Apache2.2.16+PHP5.3.3+MySQL5.1.49的配置方法
			第一步:下载安装的文件 1. MySQL:下载地址mysql-5.1.49-win32.msi: 2. Apache: 下载地址httpd-2.2.16-win32-x86-openssl-0.9.8 ... 
- 【视频分享】Liger UI实战集智建筑project管理系统配商业代码(打印报表、角色式权限管理)
			QQ 2059055336 课程讲师:集思博智 课程分类:.net 适合人群:中级 课时数量:23课时 用到技术:Liger UI框架.AJAX.JSON数据格式的序列化与反序列化.角色的交叉权限管理 ... 
- 关于SpringCloud微服务架构概念的一点理解
			目前微服务是非常火的架构或者说概念,也是在构建大型互联网项目时采用的架构方式. 1.单体架构单体架构,是指将开发好的项目打成war包,然后发布到tomcat等容器中的应用. 假设你正准备开发一款与Ub ... 
- python文章学习列表
			1.https://home.cnblogs.com/u/darkpig/feed/blog/ 这篇博主的系列文章 2. 
- [转]【Delphi】 Thread.Queue与Synchronize的区别
			前话: 其实大家要学会看源码, 我接下来要说的这些东东,与其等别人讲,还不如自己搞几个代码试一下,印象还深刻点 TThread.Queue和TThread.Synchronize的区别,效果上:二者 ... 
- mysql09---sql语句优化
			Sql语句本身的优化 问题是: 如何从一个大项目中,迅速的定位执行速度慢的语句. (定位慢查询) 首先我们了解mysql数据库的一些运行状态如何查询(比如想知道当前mysql运行的时间/一共执行了多少 ... 
- cesiumjs学习笔记之三——cesium-navigation插件 【转】
			http://blog.csdn.net/Prepared/article/details/68940997?locationNum=10&fps=1 插件源码地址:https://githu ... 
- 局域网Cesium离线影像及瓦片影像地图加载【转】
			http://www.mamicode.com/info-detail-2161992.html 1.Cesium简介 优点: cesium展示地图数据效果比较好,解析2D地图各种不同服务类型的数据源 ... 
- Android数据展示之ListView
			Android应用程序中经常需要使用ListView展示数据,一个ListView通常将数据填充到布局文件中,在填充的过程中需要知道连接数据与ListView的适配器.适配器是一个连接数据和Adapt ... 
- 理解js中的new
			new 操作符 在有上面的基础概念的介绍之后,在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在Javascript中,我们将这类方式成为Pseudoclassic ... 
