codeforces 1100D-Dasha and Chess
传送门: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的更多相关文章
- CF1100D Dasha and Chess
题目地址:CF1100D Dasha and Chess 这是我的第一道交互题 思路不难,主要讲讲这条语句: fflush(stdout); stdout是标准输出的意思.因为有时候,我们输出到std ...
- D. Dasha and Chess(交互题)
题目链接:http://codeforces.com/contest/1100/problem/D 题目大意:给你一个999*999的图,然后有666个黑色旗子,一个白色棋子,每一次白色棋子只能在它附 ...
- codeforces 761D - Dasha and Very Difficult Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 761C Dasha and Password(枚举+贪心)
题目链接 Dasha and Password 题目保证一定有解. 考虑到最多只有两行的指针需要移动,那么直接预处理出该行移动到字母数字或特殊符号的最小花费. 然后O(N^3)枚举求最小值即可. 时间 ...
- Codeforces 761D Dasha and Very Difficult Problem(贪心)
题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...
- Codeforces 761E Dasha and Puzzle(构造)
题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...
- 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 ...
- Codeforces 1173B Nauuo and Chess
题目链接:http://codeforces.com/problemset/problem/1173/B 思路参考:https://www.cnblogs.com/blowhail/p/1099123 ...
- codeforces 761B Dasha and friends
https://vjudge.net/problem/CodeForces-761B 题意: 有一个圆形跑道,上面有若干个障碍,分别给出两个人距离障碍的距离,问这两个人是否是在同一个跑道上跑步(我是这 ...
- @codeforces - 793G@ Oleg and chess
目录 @description - translation@ @solution@ @part - 1@ @part - 2@ @part - 3@ @part - 4@ @accepted code ...
随机推荐
- vue 外卖app(3) 利用slot分发内容
1. 增加一个HeaderTop.vue <template> <header class="header"> <slot name="le ...
- vue $emit 子传父
我们使用子组件传递值给父组件使用 $emit 代码 <!DOCTYPE html> <html lang="en"> <head> <me ...
- ubuntu 16.04 jdk-8u201-linux-x64.tar.gz 安装部署
都是在普通用户加sudo代替root 1.sudo tar -zxvf jdk-8u201-linux-x64.tar.gz2.sudo chown make:make jdk1.8.0/3.sudo ...
- Ruby 环境
Ruby 环境 本地环境设置 如果您想要设置 Ruby 编程语言的环境,请阅读本章节的内容.本章将向您讲解与环境设置有关的所有重要的主题.建议先学习下面几个主题,然后再进一步深入学习其他主题: Lin ...
- NX二次开发-UF_MODL_ask_point_containment获取一个点是在体(面,边)的边界内部,外部,还是边界上
NX9+VS2012 #include <uf.h> #include <uf_modl.h> #include <uf_curve.h> #include < ...
- NX二次开发-NXOpen方式遍历所有体workPart->Bodies();
NX11+VS2013 #include <NXOpen/DisplayManager.hxx> #include <NXOpen/Body.hxx> #include < ...
- Python 爬虫-爬取京东手机页面的图片
具体代码如下: __author__ = 'Fred Zhao' import requests from bs4 import BeautifulSoup import os from urllib ...
- C#-Api:身份证识别
ylbtech-C#-Api:身份证识别 通过POST上传base64格式的图片内容,可识别二代身份证.驾照.行驶证.军官证.中华人民共和国往来港澳通行证.台湾居民往来大陆通行证.大陆居民往来台湾通行 ...
- Python 数据结构_队列
目录 目录 队列 队列 Queue 队列是一种先进先出(FIFO)的数据类型, 新的元素通过 入队 的方式添加进 Queue 的末尾, 出队 就是从 Queue 的头部删除元素. 用列表来做 Queu ...
- CodeForces-1244C-The Football Season-思维
The football season has just ended in Berland. According to the rules of Berland football, each matc ...