Vika and Her Friends

发布时间 2023-08-02 10:50:35作者: smiling&weeping

Smiling & Weeping

                ----早知道思念那么浓烈,不分手就好了

 

 

题目链接:Problem - A - Codeforces

题目大意:有n个Vika的朋友在一个n*m的方格中去捉Vika,给出Vika和她朋友的初始位置(坐标),求出Vika能否逃出朋友的追捕。

思路:怎么说╮(╯▽╰)╭ 你知道这个逻辑你就能把题目做出来,不知道这个逻辑你就做不出来,现在上逻辑

  1. 小v和朋友在同一行,如果小v向朋友靠近,朋友也向小v靠近,距离减小;如果小v沿行远离朋友的方向前进,朋友继续跟上,距离减小;如果小v沿列方向行走,朋友继续沿靠近朋友行的方向前进。
  2. 小v和朋友在同一列,如果小v像朋友靠近,朋友也向小v靠近,距离减小;如果小v沿列远离朋友的方向前进,朋友继续跟上,距离减小;如果小v沿行方向行走,朋友继续沿靠近朋友列的方向前进。
  3. 小v和朋友在不同行不同列,如果小v沿行(列)方向接近朋友,朋友沿列(行)的方向朝小v前进。如果小v沿行(列)的方向远离朋友,朋友沿行(列)的方向前进,距离减少。

逻辑大概就是这样:

 

  • If Vika is in the same column as the friend. If Vika goes towards the friend, then the friend goes towards her, reducing the distance. If Vika goes in the opposite direction, then the friend also goes towards her, reducing the area to Vika. If Vika goes along the row, then the friend goes towards Vika along the column, which also reduces the area to Vika.
  • If Vika is in the same row as the friend. If Vika goes towards the friend, then the friend goes towards her, reducing the distance. If Vika goes in the opposite direction, then the friend also goes towards her, reducing the area to Vika. If Vika goes along the column, then the friend goes towards Vika along the row, which also reduces the area to Vika.
  • If Vika and the friend are in different rows and columns. If Vika goes towards the friend along the row, then the friend goes towards her along the column, reducing the distance. If Vika goes towards the friend along the column, then the friend goes towards her along the row, reducing the distance. If Vika goes away from the friend, then the friend makes a move in the same direction, thereby reducing the area to Vika.

Talk is cheap , show me the code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int t , n;
 4 int main()
 5 {
 6     scanf("%d",&t);
 7     while(t--)
 8     {
 9         int a,b;
10         scanf("%d%d%d",&a,&b,&n);
11         int x,y,xx,yy;
12         bool flag = false;
13         scanf("%d%d",&x,&y);
14         for(int i = 1; i <= n; i++)
15         {
16             scanf("%d%d",&xx,&yy);
17             if((x+y)%2 == (xx+yy)%2) flag = true;
18         }
19         if(flag)
20             printf("NO\n");
21         else
22             printf("YES\n");
23     }
24     return 0;
25 }

文章到此结束,愿我们此去行止由心