首页 技术 正文
技术 2022年11月15日
0 收藏 803 点赞 3,249 浏览 907 个字

题目地址: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 secondusing 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;}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844