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. IE浏览器GET传参后台乱码

    ie里面 get传递的字符串 为 gb2312  ,后台用的是utf-8类型  所以用 POST传递字符串到后端 否则进行js参数转码 encodeURI(""); 后端解码

  2. 合并Excel文件

    //合并Excel文件 private void MargeExcelFile(string destFile, string dirPath) { DirectoryInfo dir = new D ...

  3. libsvm-3.21使用文档

    Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. (可用于分 ...

  4. 如何使用 declare-styleable

    如何使用 declare-styleable 在创建 xml 到 objectName/res/values/ 命名为 attrs.xml 编辑文件内容为(示例)<?xml version=&q ...

  5. win7下载

    正式版WIN7的64位旗舰版 http://pan.baidu.com/share/link?shareid=60038&uk=3960800092 下面是正式win8Windows 8 64 ...

  6. MariaDB 加密特性及使用方法

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

  7. HDU----(4291)A Short problem(快速矩阵幂)

    A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. hdu--(1247)Hat’s Words(trie树)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. 批次更新BAPI_OBJCL_CHANGE

    FORM frm_edit_batch TABLES pt_field STRUCTURE dfies USING ps_batch TYPE ty_batch CHANGING ps_rturn T ...

  10. 9. shell环境

    • printenv –打印部分或所有的环境变量 • set –设置 shell 选项 • export —导出环境变量,让随后执行的程序知道. • alias –创建命令别名 1.shell环境:s ...