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 ...
随机推荐
- HDFS集群优化篇
HDFS集群优化篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.操作系统级别优化 1>.优化文件系统(推荐使用EXT4和XFS文件系统,相比较而言,更推荐后者,因为XF ...
- Centos 7最小化安装部署PostgreSQL
安装 sh-4.2# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-ce ...
- linux 网络连接数查看方法
1.查看系统tcp连接中各个状态的连接数. netstat -an|awk '/^tcp/ {++s[$NF]} END {for(a in s ) print a,s[a]}' 2.查看和本机23端 ...
- 【JS】JavaScript中Null和undefind区别
1.undefined:只有一个值,及特殊的undefined.在使用var声明变量但未对其初始化时,这个变量的值是undefined,简言之,undefined就是表示变量申明了但未初始化时的值. ...
- Golang入门教程(十一)beego 框架之RESTful Controller 路由
官方文档:https://beego.me/docs/mvc/controller/router.md 什么是路由设置呢?前面介绍的 MVC 结构执行时,介绍过 beego 存在三种方式的路由:固定路 ...
- electron-vue:Vue.js 开发 Electron 桌面应用
相信很多同学都知道 Electron 可以帮助开发人员使用前端技术开发桌面客户端应用,今天介绍的 electron-vue 框架是一套基于 Vue.js 开发 Electron 桌面应用的脚手架,该项 ...
- Groovy 设计模式 -- null对象模式
Null Object Pattern http://groovy-lang.org/design-patterns.html#_loan_my_resource_pattern 对于一些场景获得的对 ...
- 隐马尔可夫模型HMM(一)
摘自 1.李航的<统计学习方法> 2.https://www.cnblogs.com/pinard/p/6945257.html 了解HMM模型 1.隐马尔可夫模型的定义 隐马尔可夫模型是 ...
- pycharm使用方法
https://blog.csdn.net/zhaihaifei/article/details/51658425
- Debian Security Advisory(Debian安全报告) DSA-4412-1 drupal7 security update
Debian Security Advisory(Debian安全报告) DSA-4412-1 drupal7 security update Package:drupal7 CVE ID:暂无 Dr ...