交互式程序,要用到一个函数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. POJ - 2377 Bad Cowtractors Kru最大生成树

    Bad Cowtractors Bessie has been hired to build a cheap internet network among Farmer John's N (2 < ...

  2. HTML5学习笔记(四)语义元素

    语义元素能够清楚的描述其意义给浏览器和开发者. 无语义 元素实例: <div> 和 <span> - 无需考虑内容. 语义元素实例: <form>, <tab ...

  3. LeetCode: 389 Find the Difference(easy)

    题目: Given two strings s and t which consist of only lowercase letters. String t is generated by rand ...

  4. MYSQL中coalesce函数的用法

    coalesce():返回参数中的第一个非空表达式(从左向右依次类推): 例如: select coalesce(null,4,5); // 返回4 select coalesce(null,null ...

  5. C++ com

    http://www.cnblogs.com/hlxs/p/3783920.html 昨天看了<COM本质论>的第一章"COM是一个更好的C++",觉得很有必要做一些笔 ...

  6. Fire (poj 2152 树形dp)

    Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...

  7. axios 跨域配置

    axios跨域设置 找到项目config文件夹下的index.js文件,将dev中的proxyTable项中添加配置 proxyTable: { '/api': { target: 'https:// ...

  8. git clone 指定新建本地库位置

  9. windows installer cleanup utility - Windows下卸载神器

    https://windows-installer-cleanup-utility.soft32.com

  10. HTTP2 Sampler for JMeter

    今天开发大大说能不能帮忙压一下HTTP2的链接,便去查了一下相关的东西. HTTP 2.0 的出现,相比于 HTTP 1.x ,大幅度的提升了 web 性能.在与 HTTP/1.1 完全语义兼容的基础 ...