CF#212 Two Semiknights Meet

http://codeforces.com/problemset/problem/362/A

题意:两个棋子同时走田字,问是否能相遇。#没什么卵用。

开始没注意两个棋子同时走,当相差距离为2时,不可能相遇。

思路:两个棋子横坐标相差为4或者相差为0时,才可以相遇。纵坐标同理。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<cmath>
 5 using namespace std;
 6 char map[10][10];
 7 int a[10],b[10];
 8 main()
 9 {
10     int t,i,j,k,s,q,w;
11     scanf("%d",&t);
12     while(t--)
13     {
14         k=0;s=0;
15         for(i=0;i<8;i++)
16         scanf("%s",map[i]);
17         for(i=0;i<8;i++)
18         {
19             for(j=0;j<8;j++)
20             {
21                 if(map[i][j]==‘K‘)
22                 {
23                     a[k++]=i;
24                     b[s++]=j;
25                 }
26             }
27         }
28         q=abs(a[1]-a[0]);
29         w=abs(b[1]-b[0]);
30         if((q==4||q==0)&&(w==4||w==0))
31         printf("YES\n");
32         else
33         printf("NO\n");
34 }
35 }

DFS代码

注意step%2==0才可能相遇。

 1 char maze[10][10];
 2 int a[2],b[2];
 3 int vis[10][10];
 4 int flag;
 5 void dfs(int x,int y,int step)
 6 {
 7     if(x == a[1] && y == b[1]&& step%2 == 0)
 8     {
 9         flag = 1;
10         return;
11     }
12     if(x < 0 || x >= 8 || y < 0 || y >= 8)
13         return ;
14     if(vis[x][y])
15         return;
16     vis[x][y] = 1;
17     if(flag)
18         return ;
19     dfs(x - 2,y - 2,step+1);
20     dfs(x - 2,y + 2,step+1);
21     dfs(x + 2,y - 2,step+1);
22     dfs(x + 2,y + 2,step+1);
23 }
24 int main()
25 {
26     //freopen("in.txt","r",stdin);
27     int t;
28     scanf("%d",&t);
29     while(t--)
30     {
31         int id = 0;
32         rep(i,0,8)
33         {
34             scanf("%s",maze[i]);
35             rep(j,0,8)
36             {
37                 if(maze[i][j] == ‘K‘)
38                 {
39                     a[id] = i;
40                     b[id] = j;
41                     id++;
42                 }
43             }
44         }
45         clr(vis);
46         flag = 0;
47         dfs(a[0],b[0],0);
48         if(flag)
49             cout<<"YES"<<endl;
50         else
51             cout<<"NO"<<endl;
52     }
53     return 0;
54 }

时间: 2024-10-01 21:12:01

CF#212 Two Semiknights Meet的相关文章

贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

题目传送门 1 /* 2 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 using namespace std; 8 9 const int MAXN = 11; 10 const int INF = 0x3f3f3f3f; 11 char s[MAXN][MAXN]; 12 1

Codeforces Round #459 (Div. 2) AB

A. Eleven Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. Her friend suggested that her name should only consist of u

Codeforces 918A Eleven 918B Radio Station

Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. Her friend suggested that her name should only consist of uppercase a

/etc/postfix/main.cf

# cat main.cf     1  # Global Postfix configuration file. This file lists only a subset     2  # of all parameters. For the syntax, and for a complete parameter     3  # list, see the postconf(5) manual page (command: "man 5 postconf").     4  #

CF 609E, 树链剖分

题目大意:给你一个联通无向图,问你包含某条边的最小生成树的大小是多少 解:做一个最小生成树,如果询问边在树上,则答案是最小生成树,否则则是这条边+树构成的环上去掉一条最大树边后得到的树.这里用树剖处理即可. 有个sb错误,因为问题是边权,而树剖的链一般是以点为单位,如果采用边权下放到点的技巧的话,注意lca的点权不要计算进来. 1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #incl

(CF#257)B. Jzzhu and Sequences

Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109?+?7). Input The first line contains two integers x and y (|x|,?|y|?≤?109). The second line contains a single i

(CF#257)C. Jzzhu and Chocolate

Jzzhu has a big rectangular chocolate bar that consists of n?×?m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edg

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

2-12. 两个有序链表序列的交集(20) (ZJUPAT 用vector实现)

题目链接:http://pat.zju.edu.cn/contests/ds/2-12 已知两个非降序链表序列S1与S2,设计函数构造出S1与S2的交集新链表S3. 输入格式说明: 输入分2行,分别在每行给出由若干个正整数构成的非降序序列,用-1表示序列的结尾(-1不属于这个序列).数字用空格间隔. 输出格式说明: 在一行中输出两个输入序列的交集序列,数字间用空格分开,结尾不能有多余空格:若新链表为空,输出"NULL". 样例输入与输出: 序号 输入 输出 1 1 2 5 -1 2 4