题目地址: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;
}

最新文章

  1. linux一些常用命令
  2. 模拟ATM机银行系统
  3. Java集合框架使用总结
  4. SQLDMOHelper
  5. 「linux」win+linux 双系统 默认启动项 的修改
  6. 272. Closest Binary Search Tree Value II
  7. GridView、DataGrid、DataList、Repeater、ListView、DetailsView、FormView
  8. effect state dx11
  9. zookeeper配置同步zookeeper编程
  10. 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
  11. 【android】java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
  12. HDOJ-1014 Uniform Generator
  13. Java基础之垃圾回收
  14. hdu4336 Card Collector 状态压缩dp
  15. linux shell 执行多个命令的方法
  16. ABP Zero 单部署,单数据库,多租户架构
  17. ASP.NET Core 运行原理解剖[3]:Middleware-请求管道的构成
  18. 安装Spring Tool Suite(STS)
  19. Mapbox浅析(快速入门Mapbox)
  20. c# winform导出Excel

热门文章

  1. 关键字(8):数据库记录的增删查改insert,delete,select,update
  2. OpenOCD-JTAG调试
  3. Reference-TMB
  4. 【C#】C#创建自定义Object对象
  5. Linux记录-jstack采集namenode堆栈信息
  6. SQL语句实例集合
  7. idea 快捷键ctrl+shift+f失效的解决方案
  8. HDU 1036(平均速度 **)
  9. json 模块 与 pickle 模块
  10. Struts2的JSON插件