传送门:QAQQAQ

题意:This is an interactive task.

999*999国际象棋棋盘中有一个王和666个车,玩家走王,电脑走车,玩家先走,玩家的目的是让对方的车将到自己的王,电脑的车可以“飞”(即移动到棋盘上任意一点),但吃子规则不变,玩家必须要在2000步之内获胜

思路:哇塞这是国际象棋!好激动好激动!(然而没做出来)

我们考虑一般情况:根据王的位置一横一竖把棋盘分成4个部分,加入王往一个方向走(这里假设往左上走),则除了背对他的方向其它所有车都要闪开(即左上,右上,左下)

假如我们从左上角开始赶车:有666个车要被赶走,王走到右下角(即把车赶光)要998步,太多了;

那么如果王在最中间呢?——最少的一个方向最多也就166个,也就是王在中间背对车个数最少的方向走最少也可以赶走500个车,而王走到最底下只要499步——有2个车来不及闪开了

所以我们先把王移到正中间,再背对车个数最少的方向逼近就行了

活生生打成了码农题(200多行,有很多函数是多余的),一直说越界(其实电脑骗人,只要wronganswer就说越界),加了很多特判,结果发现把王的位置也读入的时候mp赋值为1了

代码:

#include<bits/stdc++.h>
using namespace std;
const int inf=;
int dx[]={-,-,,};
int dy[]={-,,-,};
 
struct node{
int x,y;
}a[];
int mp[][];
 
void init()
{
memset(mp,,sizeof(mp));
for(int i=;i<=;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if (i) mp[a[i].x][a[i].y]++;//之前没判i!=0
}
}
 
void print()
{
printf("%d %d\n",a[].x,a[].y);
fflush(stdout);
}
 
void up()
{
a[].x--;
print();
}
 
void down()
{
a[].x++;
print();
}
 
void left()
{
a[].y--;
print();
}
 
void right()
{
a[].y++;
print();
}
 
void leftup()
{
if(mp[a[].x-][a[].y-])
{
up();
return;
}
a[].x--; a[].y--;
print();
}
 
void leftdown()
{
if(mp[a[].x+][a[].y-])
{
down();
return;
}
a[].x++; a[].y--;
print();
}
 
void rightdown()
{
if(mp[a[].x+][a[].y+])
{
down();
return;
}
a[].x++; a[].y++;
print();
}
 
void rightup()
{
if(mp[a[].x-][a[].y+])
{
up();
return;
}
a[].x--; a[].y++;
print();
}
 
void read()
{
int id,xx,yy;
scanf("%d%d%d",&id,&xx,&yy);
if(id==-)
{
exit();
}
mp[a[id].x][a[id].y]--;
a[id].x=xx; a[id].y=yy;
mp[a[id].x][a[id].y]++;
}
 
void ready()
{
while(a[].x<)
{
down();
read();
}
while(a[].x>)
{
up();
read();
}
while(a[].y>)
{
left();
read();
}
while(a[].y<)
{
right();
read();
}
}
 
int dir,minn=inf,tmp;
void judge_direction()
{
int cnt[]={,,,};//0:leftup 1:rightup 2:leftdown 3:rightdown
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(i<)
{
if(j<) cnt[]+=mp[i][j];
if(j>) cnt[]+=mp[i][j];
}
if(i>)
{
if(j<) cnt[]+=mp[i][j];
if(j>) cnt[]+=mp[i][j];
}
}
}
for(int i=;i<;i++)
{
if(minn>cnt[i]) minn=cnt[i],tmp=i;
}
dir=-tmp;
}
 
void move(int dir)
{
if(dir==) leftup();
else if(dir==) rightup();
else if(dir==) leftdown();
else rightdown();
}
 
void solve()
{
while()
{
move(dir);
read();
}
}
 
int main()
{
init();
ready();
judge_direction();
solve();
return ;
}

codeforces 1100D-Dasha and Chess的更多相关文章

  1. CF1100D Dasha and Chess

    题目地址:CF1100D Dasha and Chess 这是我的第一道交互题 思路不难,主要讲讲这条语句: fflush(stdout); stdout是标准输出的意思.因为有时候,我们输出到std ...

  2. D. Dasha and Chess(交互题)

    题目链接:http://codeforces.com/contest/1100/problem/D 题目大意:给你一个999*999的图,然后有666个黑色旗子,一个白色棋子,每一次白色棋子只能在它附 ...

  3. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. Codeforces 761C Dasha and Password(枚举+贪心)

    题目链接 Dasha and Password 题目保证一定有解. 考虑到最多只有两行的指针需要移动,那么直接预处理出该行移动到字母数字或特殊符号的最小花费. 然后O(N^3)枚举求最小值即可. 时间 ...

  5. Codeforces 761D Dasha and Very Difficult Problem(贪心)

    题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...

  6. Codeforces 761E Dasha and Puzzle(构造)

    题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...

  7. Codeforces 734D. Anton and Chess(模拟)

    Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the pro ...

  8. Codeforces 1173B Nauuo and Chess

    题目链接:http://codeforces.com/problemset/problem/1173/B 思路参考:https://www.cnblogs.com/blowhail/p/1099123 ...

  9. codeforces 761B Dasha and friends

    https://vjudge.net/problem/CodeForces-761B 题意: 有一个圆形跑道,上面有若干个障碍,分别给出两个人距离障碍的距离,问这两个人是否是在同一个跑道上跑步(我是这 ...

  10. @codeforces - 793G@ Oleg and chess

    目录 @description - translation@ @solution@ @part - 1@ @part - 2@ @part - 3@ @part - 4@ @accepted code ...

随机推荐

  1. jq-demo-阻止冒泡,阻止默认行为

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. Python自学:第五章 动手试一试 4-3

    # -*- coding: GBK -*- numbers = ['] for number in numbers: print(number) 输出为: 1 2 3 4 5 6 7 8 9 10 1 ...

  3. delphi 键盘常用参数(PC端和手机端 安卓/IOS)

    常数名称(红色手机端) 十六进制值 十进制值 对应按键(手机端) Delphi编程表示(字符串型)_tzlin注 0 0 大键盘Delete键 #0 VK_LBUTTON 1 1 鼠标的左键 #1 V ...

  4. Struts功能详解——ValidatorForm

    ActionForm和ValidatorForm区别:       一个Form继承了ValidatorForm 就不用写具体的验证,但是需要提供:validation-rules.xml 和 val ...

  5. Kafka高级API和低级API

    Kafka消费过程分析 kafka提供了两套consumer API:高级Consumer API和低级API. 1 高级API 1)高级API优点 高级API 写起来简单 不需要去自行去管理offs ...

  6. Python字典列表字段重组形成新的字典

    最近遇到这样一个需求,需要将字典列表中的字段进行重组,形成一个新的字典.举个例子吧: l1 = [{"x": 22, "y": 22, "demand ...

  7. HDFS API 操作实例(一) HDFS读写操作

    1. 读取HDFS文件 1.1 字符读取HDFS上的文件 Configuration conf = new Configuration(); Path path = new Path(pathstr) ...

  8. java-day13

    异常 指的是程序在执行过程中,出现的非正常情况,最终会导致JVM的非正常停止 异常分类:编译异常,运行期异常 异常的产生过程分析 throw关键字:指方法中抛出指定异常 使用格式:throw new ...

  9. 《转》python对象

    http://www.cnblogs.com/BeginMan/p/3160044.html 一.学习目录 1.pyhton对象 2.python类型 3.类型操作符与内建函数 4.类型工厂函数 5. ...

  10. [课后作业] 第001讲:我和Python的第一次亲密接触 | 课后测试题的答案

    0. Python 是什么类型的语言? Python是脚本语言 脚本语言(Scripting language)是电脑编程语言,因此也能让开发者藉以编写出让电脑听命行事的程序.以简单的方式快速完成某些 ...