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 ...
随机推荐
- BeanFactory 和 ApplicationContext 区别
区别 BeanFactory: Spring里面最低层的接口,提供了最简单的容器的功能,只提供了实例化对象和拿对象的功能 BeanFactory在启动的时候不会去实例化Bean,中有从容器中拿Bean ...
- QueryList 内容过滤
<?php require 'vendor/autoload.php'; use QL\QueryList; $html =<<<STR <div id="de ...
- NX二次开发-UFUN获取工程图的数量和tag UF_DRAW_ask_drawings
NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> #include < ...
- NX二次开发-UFUN编辑添加哪些图层UF_LAYER_edit_category_layer
1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_layer.h> 5 6 7 UF_initialize(); 8 9 //创 ...
- NX二次开发-UFUN所有对象类型的宏定义
/**************************************************************************** Copyright (c) 2010 Sie ...
- 笔试题-求小于等于N的数中有多少组素勾股数
题目描述: 一组勾股数满足:a2+b2=c2: 素勾股数:a,b,c彼此互质. 输入正整数N: 输出小于等于N的数中有多少组勾股数. 例: 输入:10 输出:1 思路:我是直接暴力破解的…… 首先找出 ...
- JavaScript笔记 - Object对象特性的应用
可以依据js对象中key是永远不会重复的原则,来模拟Map类型以及去除数组重复项. 1.模拟Map类型 (1)构造Map对象 function Map(){ //private var obj = { ...
- Allow Pin Swapping Using these Methods options
Frm:http://techdocs.altium.com/display/ADOH/Pin,+Pair+and+Part+Swapping#Pin,PairandPartSwapping-Swap ...
- CodeForces 1152F2 Neko Rules the Catniverse (Large Version)
题目链接:http://codeforces.com/problemset/problem/1152/F2 题目大意 见http://codeforces.com/problemset/problem ...
- CSS Sprites(CSS图像拼合技术)教程、工具集合
本集合是有一位国外设计师收集整合,并由 oncoding翻译成中文的,感谢他们的辛苦贡献.CSS Sprites技术在国外并不是什么新技术,只不过近两年(尤其08年开始)中国开始流行这个词,大家也开始 ...