题目地址:CF1100D Dasha and Chess

这是我的第一道交互题

思路不难,主要讲讲这条语句:

fflush(stdout);

stdout是标准输出的意思。因为有时候,我们输出到stdout的内容不能及时输出,使因为stdout的缓冲区没有满或者其他原因,fflush(stdout)就是强迫把stdout内容输出并清空stdout。

代码:

#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1006, K = 666;
pii a, b[K+6];
bool v[N][N];
int c[6];

inline void upd(int dx, int dy) {
    a.x += dx;
    a.y += dy;
    if (v[a.x][a.y]) a.x -= dx;
    printf("%d %d\n", a.x, a.y);
    fflush(stdout);
    int o, p, q;
    scanf("%d %d %d", &o, &p, &q);
    if (o == -1 && p == -1 && q == -1) exit(0);
    v[b[o].x][b[o].y] = 0;
    v[b[o].x=p][b[o].y=q] = 1;
}

int main() {
    cin >> a.x >> a.y;
    for (int i = 1; i <= K; i++) {
        scanf("%d %d", &b[i].x, &b[i].y);
        v[b[i].x][b[i].y] = 1;
    }
    while (a.x > 500) upd(-1, 0);
    while (a.x < 500) upd(1, 0);
    while (a.y > 500) upd(0, -1);
    while (a.y < 500) upd(0, 1);
    for (int i = 1; i <= K; i++) {
        int k = 0;
        if (b[i].x < 500) k |= 2;
        if (b[i].y < 500) k |= 1;
        c[k]++;
    }
    int t = 0, w = c[0];
    for (int i = 1; i < 4; i++)
        if (c[i] < w) w = c[t=i];
    int dx = (t >> 1) ? 1 : -1, dy = (t & 1) ? 1 : -1;
    while (1) upd(dx, dy);
    return 0;
}

CF1100D Dasha and Chess的更多相关文章

  1. D. Dasha and Chess(交互题)

    题目链接:http://codeforces.com/contest/1100/problem/D 题目大意:给你一个999*999的图,然后有666个黑色旗子,一个白色棋子,每一次白色棋子只能在它附 ...

  2. Codeforces 1100 - A/B/C/D/E/F - (Undone)

    链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...

  3. Codeforces Round #532

    以后不放水题了 C.NN and the Optical Illusion 复习一下高中数学即可 $\frac{ans}{ans+r}=\sin \frac{\pi}{n}$ 解方程 #include ...

  4. Codeforces Round #532 (Div. 2) Solution

    A. Roman and Browser 签到. #include <bits/stdc++.h> using namespace std; ]; int get(int b) { ]; ...

  5. Codeforces Round #532 (Div. 2) 题解

    Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...

  6. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  8. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

  9. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. Linux下进程与线程的区别及查询方法

    在平时工作中,经常会听到应用程序的进程和线程的概念,那么它们两个之间究竟有什么关系或不同呢?一.深入理解进程和线程的区别 1)两者概念 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进 ...

  2. 5款Mac极速下载工具推荐和下载

    最近几年用到下载工具的情况其实很少了,比如几年前我们可能经常用下载工具下载视频.音乐.图书等资源,但今天的我们更多的在线看视频.在线听音乐了,偶尔用到下载的时候直接用浏览器自带的下载工具也完全够用了, ...

  3. 2017-12-18python全栈9期第三天第一节之昨天内容回顾与作业讲解用户三次机会再试试

    #!/user/bin/python# -*- coding:utf-8 -*-username = "zd"password = "123"i = 3whil ...

  4. u-boot(一)启动简介

    目录 u-boot(一)启动简介 启动概述 内部存储布局 Bootloader概述 内核启动参数 taggedlist 体验一下实际的Uboot U-boot的使用帮助 U-boot基本要求 titl ...

  5. @jsonProperty 实现返回自定义属性名字

    实现场景: 比如说前端需要返回userPic 这个字段,但是我们数据库定义的是pic字段. 可以用@jsonProperty 来实现 public class User{ @JsonProperty( ...

  6. linux部署Web项目总结

    本文用的是CentOS7系统,不是虚拟机. 1.什么是Xshell? xshell连接上linux之后,就等同于linux本身的终端命令窗口. xshell不是必需品,但是它能更好的辅助我们学习lin ...

  7. mysq存储金额的数值类型选择

    在之前得项目中用到了double,计算之后有很长得小数位,需要用算法去除,非常麻烦,以后推荐使用:decimal 这个是专门处理金额值的,Java 类型对应BigDecimal

  8. Dev-Tips

    186 Chrome DevTools: How to use Logpoints for quicker JavaScript debugging You can use the new Logpo ...

  9. Junit4学习与使用【转】

    参考: http://blog.csdn.net/qqhjqs/article/details/42219037

  10. Sqlcmd使用详解

    Sqlcmd实用工具,可以输入 TRANSACT-SQL 语句. 系统过程和脚本文件,通过各种可用模式: 通过命令提示符. 在中查询编辑器在 SQLCMD 模式下. 在 Windows 脚本文件. 在 ...