交互式程序,要用到一个函数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. httpservlet的service()、doget()、dopost方法

    HttpServlet里的三个方法:service(HttpServletRequest req, HttpServletResponse resp) ,doGet(HttpServletReques ...

  2. 在Android工程中导入外部动态连接库(so文件)

    假设要导入的so文件命为libtest.so,导入的方法如下: 给工程加入Native Support,将libtest.so复制到在jni文件夹下,在Android.mk文件中,加入以下代码: in ...

  3. LeetCode: 669 Trim a Binary Search Tree(easy)

    题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so th ...

  4. 2018杭电多校第三场1003(状态压缩DP)

    #include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...

  5. Google Analytics & Webtrend 使用笔记

    GA和webtrend中的参数,每每遇到了都记不住.遇到一点记一点好了... Page Views(PV): 浏览次数.用户每打开一个页面,记录为1个PV:用户多次打开同一个页面,PV累计多次. Da ...

  6. 阿里云(centos)下svn 服务器搭建

    安装说明 系统环境:阿里云centos安装方式:yum install subversion 检查已安装版本 #检查是否安装了低版本的SVN[root@localhost /]# rpm -qa su ...

  7. Condition应用和源码分析

    1.Condition实现一个队列public class BoundedQueue<T> { public List<T> q; //这个列表用来存队列的元素 private ...

  8. 14.插入数据、复制数据--SQL

    一.插入完整的行 要求指定表名和插入到新行中的值 INSERT INTO Customers ', 'Toy Land', '123 Any Street', 'New York', 'NY', ', ...

  9. echart option属性

    option 图表选项,包含图表实例任何可配置选项: 公共选项 , 组件选项 , 数据选项 名称 描述 {color}backgroundColor 全图默认背景,(详见backgroundColor ...

  10. Hive进阶_汇总

    =========================================================================== 第2章 Hive数据的导入 使用Load语句执行 ...