hdu 3766 Knight's Trip
来源:互联网 发布:json字符串中url编码 编辑:程序博客网 时间:2024/06/06 01:37
最近练习BFS,看某位大神博客的小结跟着做来着,然后碰到这个...就是跳马的问题.没给出棋盘,就是说没有范围,n,m可以很大,用BFS数据大一点看着很慢,感觉肯定是过不了,大神博客写着:之前需要逼近下,然后再搜索,或者直接枚举判断下就行了。...俩都不会,无法,看看怎么逼近,尝试一小时还是不会。找个数学大神看看有啥规律可循没有。推出来公式之后一直WA....拿着原先的搜索对照测试结果一样不理解...万万没想到啊万万没想到,卧槽换了一种输入方式就AC了...心中万只草泥马奔腾而过啊,一晚上的时间啊 全部浪费这个题了...
题目几个比较坑的地方:范围真的很大,最起码32M内存你开不起。跳马可以跳到坐标是负的地方- -只能说卧槽.还有就是有几个点要单独处理。附上代码:
#include<stdio.h>#include<string.h>int main(){ char c[20]; while(scanf("%s",c),c[0]!='E') { int x=0,y,flag=1; int k;for(int i=0;c[i];i++){if(c[i]=='-'&&i==0)flag=-1;else x=x*10+c[i]-48;}x=x*flag; scanf("%d",&y); if(x<0) x=-x; if(y<0) y=-y; if(y<x) {k=x;x=y;y=k;} if(y<=2*x) { if(x==1&&y==1) printf("2\n"); else if(x==2&&y==2) printf("4\n"); else printf("%d\n",(x+y)/3+(x+y)%3); } else { int ans=x; int c=(y-2*x)%4; ans+=c; ans+=(y-2*x-c)/2; if(y==1&&x==0) ans=3; printf("%d\n",ans); } } return 0;}
0 0
- hdu 3766 Knight's Trip
- hdoj 3766 Knight's Trip 【】
- hdu 3766 Knight's Trip(并不是bfs)
- hdu Biker's Trip Odometer
- HDU 3660 Alice and Bob's Trip
- HDU 1038 Biker's Trip Odometer
- hdu 3660 Alice and Bob's Trip
- Biker's Trip Odometer hdu 1038
- HDU 3660 Alice and Bob's Trip
- HDU 1038 Biker's Trip Odometer
- hdu acm steps Biker's Trip Odometer
- HDU 2488 A Knight's Journey
- HDU 2488 A Knight's Journey DFS
- HDU 2488 A Knight's Journey(dfs)
- Knight's Trip 马在无线大棋盘上跳到指定点最小步数问题
- knight's
- [HDU] 3660 Alice and Bob's Trip -- 树形DP?
- 杭电ACM HDU 1038 Biker's Trip Odometer
- hd 2719 The Seven Percent Solution
- Developing android applications from command line
- MakeFile基础知识(五)
- 警惕!iPhone 6即将上市 诈骗邮件已现身网络
- java跳出多重循环
- hdu 3766 Knight's Trip
- android基础笔记:显示意图并传递简单参数
- UVA 10474 - Where is the Marble?
- Android Gralloc模块分析--深入分析
- keychain应用
- 对hibernate懒加载的理解
- git命令
- 【代码备忘】VC判断自己窗口的另一种方法
- 上学的时候Java写的打字练习