CF1100D Dasha and Chess
题目地址: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的更多相关文章
- D. Dasha and Chess(交互题)
题目链接:http://codeforces.com/contest/1100/problem/D 题目大意:给你一个999*999的图,然后有666个黑色旗子,一个白色棋子,每一次白色棋子只能在它附 ...
- Codeforces 1100 - A/B/C/D/E/F - (Undone)
链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...
- Codeforces Round #532
以后不放水题了 C.NN and the Optical Illusion 复习一下高中数学即可 $\frac{ans}{ans+r}=\sin \frac{\pi}{n}$ 解方程 #include ...
- Codeforces Round #532 (Div. 2) Solution
A. Roman and Browser 签到. #include <bits/stdc++.h> using namespace std; ]; int get(int b) { ]; ...
- Codeforces Round #532 (Div. 2) 题解
Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
随机推荐
- C++: 带参数回调函数和不带参数的回调函数;
在C++中,回调函数的应用比较广泛且重要. 通过传递函数指针到其他地方,能够实现远程回调的作用,能够实现远程调用而不需要事件触发信号或者其他机制来实现,方便而快捷: 首先,回调函数有两种形式: 静态 ...
- MHA环境搭建
准备工作 数据库架构 角色 ip地址 主机名 server_id Master Slave1 Slave2 配置三台服务器ssh免秘钥认证 ssh-keygen -t rsa ssh-copy-id ...
- mac 安装pip
mac 安装pip报错 bogon:~ root# sudo easy_install pip Searching for pip Reading https://pypi.python.org/si ...
- springmvc上传图片《2》
创建springboot项目 编写配置 server: port: 8082 spring: application: name: upload-service servlet: multipart: ...
- linux unknown host 问题【转】
如果某台Linux(CentOS)服务器ping域名, 如下提示: # ping www.sina.comping: unknown host www.sina.com 确认网络没问题的情况下, 可以 ...
- Java高并发秒杀API之业务分析与DAO层
根据慕课网上关于java高并发秒杀API的课程讲解用maven+ssm+redis实现的一个秒杀系统 参考了codingXiaxw's blog,很详细:http://codingxiaxw.cn/2 ...
- Spark源码剖析 - SparkContext的初始化(十)_Spark环境更新
12. Spark环境更新 在SparkContext的初始化过程中,可能对其环境造成影响,所以需要更新环境,代码如下: SparkContext初始化过程中,如果设置了spark.jars属性,sp ...
- Vertica系列: 自动生成Identity 字段值的方法
参考 https://thisdataguy.com/2015/01/05/vertica-some-uses-of-sequences/ 在 vertica 中有三种定义 identity 字段的方 ...
- 微信小程序开发(4) 企业展示
在这篇微信小程序开发教程中,我们将介绍如何使用微信小程序开发企业内部宣传展示等功能. 一.小程序主体部分 一个小程序主体部分由三个文件组成,必须放在项目的根目录,如下: 1. 小程序逻辑 App({ ...
- windows下通过压缩包安装MySQL
一.下载压缩包 二.解压缩后存放在该路径下 三.配置环境变量 将D:\Program Files\mysql-8.0.11-winx64\bin添加到用户PATH变量或系统PATH变量中 ...