题目地址: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. C# Excel转换成Json工具(含源码)

    可执行版本下载:https://github.com/neil3d/excel2json/releases 完整项目源代码下载:https://github.com/neil3d/excel2json ...

  2. IDEA常用快捷键整理(Mac OS X版本)

    最近eclipse把我弄疯了!各种提示没有!烦,果断用了IDEA. 一.前提 IDEA版本:IntelliJ IDEA 15.0.3 Keymaps:Mac OS X 二.视图切换快捷键 1.cmd ...

  3. Java流程语句

    流程控制语句 if语句: if语句的执行流程 例子: public class IfDemo01 { public static void main(String[] args) { int x = ...

  4. jmeter中判断数据库是否存在相应的记录

    jmeter判断数据库中是否存在相应记录可以使用count 配合case,然后再加个断言,后面用 变量JMeterThread.last_sample_ok来判断是否存在相应记录 select cas ...

  5. saltstack pillar

    piller组件定义与客户端相关的任何数据(定义在master端),定义好的数据可以被其他组件调用(如state,api) 说通俗了,一句话,就是ansible vars里定义的变量,可以在整个pla ...

  6. 解决phpmyadmin 遇见的问题

    1.phpmyadmin4.8.3 上传到网站目录后提示解决phpmyadmin mysqli_real_connect(): (HY000/2002): No such file or direct ...

  7. JDBC-Transaction

    /** * 数据库中事务,指一组逻辑操作单元,使数据从一种状态变换到另一种状态 * 操作全部完成时,数据被保留,一致性可以保持,一部分操作失败时,整个操作全部视为错误,所有被操作数据回退到开始状态,放 ...

  8. mysql的定时任务

    参考博客:https://blog.csdn.net/qq_26562641/article/details/53301407 查看event是否开启: show variables like '%s ...

  9. canvas绘图history妙用

    function palette(canvas,ctx){ //初始化画布内部元素默认样式 this.strokeColor = 'red'; //默认选中红色触发颜色 this.fillColor ...

  10. 【1】【leetcode-79】 单词搜索

    (典型dfs,知道思想写错) 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单 ...