交互式程序,要用到一个函数fflush,它的作用是对标准输出流的清理,对stdout来说是及时地打印数据到屏幕上,一个事实:标准输出是以『行』为单位进行的,也即碰到\n才打印数据到屏幕。这就可能造成延时。在Windows平台上是看不出来的,它被改成及时生效了。而fflush对stdin的作用是清除冗余输入。

#include<cstdio>

const int maxn = ; //要AC
const int maxlen = ;
bool vis[maxn][maxn];
char dir[][maxlen] = {"NORTH","EAST","SOUTH","WEST"};
char done[] = "DONE"; int dx[] = {,,,-} , dy[] = {,,-,};
char response[maxlen]; bool Move(int d)
{
puts(dir[d]);
fflush(stdout);
gets(response);
return *response == 'E';
} void dfs(int x,int y)
{
vis[x][y] = true;
for(int i = ; i < ; i++) {
int nx = x + dx[i], ny = y + dy[i];
if(!vis[nx][ny] && Move(i)) dfs(nx,ny),Move((i+)%);
else vis[nx][ny] = true;
}
} int main()
{
int x = , y = ;
dfs(x,y);
puts(done);
fflush(stdout);
return ;
}

codeforecs Gym 100286B Blind Walk的更多相关文章

  1. Codeforces Gym 100286B Blind Walk DFS

    Problem B. Blind WalkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/cont ...

  2. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  3. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  4. On the way to the park Gym - 101147I 几何

    http://codeforces.com/gym/101147/problem/I I. On the way to the park time limit per test 5 seconds m ...

  5. python os.walk()

    os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...

  6. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  7. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  8. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  9. LYDSY模拟赛day1 Walk

    /* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...

随机推荐

  1. SQL Server中的聚集索引(clustered index) 和 非聚集索引 (non-clustered index)

    本文转载自  http://blog.csdn.net/ak913/article/details/8026743 面试时经常问到的问题: 1. 什么是聚合索引(clustered index) / ...

  2. 写守护进程时碰到open函数的参数,没记住

    今天写一个最简单的守护进程, 要成为一个守护进程,其实很简单了.主要步骤就4步: 1,创建进程. 2,父进程退出. 3,成为会话的头领进程. 4,将工作目录改成根目录,并把标准输入输出重定向到空设备. ...

  3. C# 写 LeetCode easy #1 Two Sum

    1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...

  4. (转)机器学习——深度学习(Deep Learning)

    from:http://blog.csdn.net/abcjennifer/article/details/7826917 Deep Learning是机器学习中一个非常接近AI的领域,其动机在于建立 ...

  5. Navicat导出数据库结构为PDF

    1.选中需要导出的数据表,右键选择 打印表 2.点击左上角 打印,选择标红的打印机,点击确定,然后键入文件名,确定之后会生成后缀为xps的文件 3.然后打开这个网址(https://xpstopdf. ...

  6. UE4 c++ 创建刚体Cube

    1 新建一个Actor,一会用蓝图继承这个 TCubeActor.h #pragma once #include "CoreMinimal.h" #include "Ga ...

  7. 同余方程 (codevs1200)

    题目描述××× 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式××× 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输出只有一行 ...

  8. JS数组去重精简版

    看了很多人写的好几个去重方法,我在这里精简组合下,适用于已排序与未排序的数组. 废话不多说,上代码. <!DOCTYPE html> <html> <head> & ...

  9. 基于IDEA实现SSM整合框架的搭建配置流程

    1.创建数据库表,以员工信息表为例子: DROP TABLE IF EXISTS `em_info`; CREATE TABLE `em_info` ( `em_id` INT(50) NOT NUL ...

  10. 1366 - Incorrect string value:'\xE5\xBC\xA0\xE4\xB8\x89' for column 'name' a 错误修改

    把name的字符集修改成 utf8 ,然后把表关了从新打开,就可以了 如果还不行,就从新创表,在创表的时候修改name的字符集 如果还不行,就修改my.ini 它在你的mysql安装路径里 [mysq ...