as Scott Meyers said in his book Effective STL,

“My advice on choosing among the sorting algorithms is to make your selection based on what you need to accomplish, not on performance considerations. If you choose an algorithm that does only what you need to do (e.g., a partition instead of a full sort), you’re likely to end up with code that’s not only the clearest expression of what you want to do, it’s also the most efficient way to accomplish it using the STL.”

Code the problem as it be maybe the most efficient way,

like the TEX principle, what you think is what you get.

#include <cstdio>
#include <algorithm> #define MAXSIZE 12 char grid[MAXSIZE][MAXSIZE]; int main() {
//freopen("input.txt","r",stdin);
int nrow,ncol,ypos,xpos, i;
char *p;
while(scanf("%d%d%d",&nrow,&ncol,&ypos)!=EOF && nrow>0) {
memset(grid,0,sizeof(grid));
for(i=1;i<=nrow;++i) { scanf("%s",&grid[i][1]); }
for(xpos=1,i=1;;++i) {
p=&grid[xpos][ypos];
switch(*p) {
case 'E': ++ypos; *p=i; break;
case 'W': --ypos; *p=i; break;
case 'N': --xpos; *p=i; break;
case 'S': ++xpos; *p=i; break;
case '\0': goto EXITCODE0;
default: goto EXITCODE1;
}
}
EXITCODE0: printf("%d step(s) to exit\n",i-1); continue;
EXITCODE1: printf("%d step(s) before a loop of %d step(s)\n",*p-1,i-*p); continue;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。// p.s. If in any way improment can be achieved, better performance or whatever, it will be well-appreciated to let me know, thanks in advance.

hdu 1035 (usage of sentinel, proper utilization of switch and goto to make code neat) 分类: hdoj 2015-06-16 12:33 28人阅读 评论(0) 收藏的更多相关文章

  1. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  2. hdu 1051 (greedy algorithm, how a little modification turn 15ms to 0ms) 分类: hdoj 2015-06-18 12:54 29人阅读 评论(0) 收藏

    the 2 version are essentially the same, except version 2 search from the larger end, which reduce th ...

  3. hdu 1050 (preinitilization or postcleansing, std::fill) 分类: hdoj 2015-06-18 11:33 34人阅读 评论(0) 收藏

    errors, clauses in place, logical ones, should be avoided. #include <cstdio> #include <cstr ...

  4. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  5. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1039 (string process, fgets, scanf, neat utilization of switch clause) 分类: hdoj 2015-06-16 22:15 38人阅读 评论(0) 收藏

    (string process, fgets, scanf, neat utilization of switch clause) simple problem, simple code. #incl ...

  8. hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏

    use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...

  9. hdu 1033 (bit masking, utilization of switch, '\0' as end of c string) 分类: hdoj 2015-06-15 21:47 37人阅读 评论(0) 收藏

    bit masking is very common on the lower level code. #include <cstdio> #include <algorithm&g ...

随机推荐

  1. Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别总结

    Mysql中utf8_general_ci与utf8_unicode_ci有什么区别呢?在编程语言中,通常用unicode对中文字符做处理,防止出现乱码,那么在MySQL里,为什么大家都使用utf8_ ...

  2. nginx安装笔记

    双节点安装 1 节点一 1.1 目录 /usr/local cd /usr/local 1.2 openssl rpm -ql openssl /usr/share/doc/openssl-1.0.0 ...

  3. SVN操作手册

    目 录 第1章 简介    1 第2章 SVN服务端    2 2.1 安装VisualSVN    2 2.2 VisualSVN服务    3 2.3 版本库    4 2.3.1 创建版本库   ...

  4. Android M 特性 Doze and App Standby模式详解

    版权声明:本文由郑桂涛原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/185 来源:腾云阁 https://www.qclo ...

  5. VirtualBox相关问题总结

    欢迎关注我的社交账号: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://gith ...

  6. fushioncharts的使用教程

    FusionCharts 是使用javascript 实现统计图表的js组件:其官网地址:http://www.fusioncharts.com.其早期版本FusionCharts Free 是基于f ...

  7. C#程序以管理员权限运行【我采用了第二种,比较好用】

    在Vista 和 Windows 7 及更新版本的操作系统,增加了 UAC(用户账户控制) 的安全机制,如果 UAC 被打开,用户即使以管理员权限登录,其应用程序默认情况下也无法对系统目录.系统注册表 ...

  8. hdu 1421

    时隔多日,又回来啃dp... 题意:有n件物品,搬k次,每搬一个消耗的疲劳值为两件物品重量之差的平方,求最小的疲劳消耗 状态转移方程:dp[i][j] = min((dp[i-2][j-1]+(s[i ...

  9. robot API笔记3

    robot.htmldata package 包编写HTML格式的输出文件. 这个包被认为是稳定的但不是公共API的一部分. Submodules robot.htmldata.htmlfilewri ...

  10. 网络与RPC

    网络与RPC 标签 : Java基础 Java为网络编程提供的java.net包封装了底层通信细节, 包含了大量的基础组件以及TCP/UDP协议的编程接口, 使得开发者可以专注于解决问题, 而不用关注 ...