Bad Boy

B. Bad Boy
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.

Anton’s room can be represented as a grid with n rows and m columns. Let (i,j) denote the cell in row i and column j. Anton is currently standing at position (i,j) in his room. To annoy Anton, Riley decided to throw exactly two yo-yos in cells of the room (they can be in the same cell).

Because Anton doesn’t like yo-yos thrown on the floor, he has to pick up both of them and return back to the initial position. The distance travelled by Anton is the shortest path that goes through the positions of both yo-yos and returns back to (i,j) by travelling only to adjacent by side cells. That is, if he is in cell (x,y) then he can travel to the cells (x+1,y), (x−1,y), (x,y+1) and (x,y−1) in one step (if a cell with those coordinates exists).

Riley is wondering where he should throw these two yo-yos so that the distance travelled by Anton is maximized. But because he is very busy, he asked you to tell him.

Input
The first line contains a single integer t (1≤t≤104) — the number of test cases. Then t test cases follow.

The only line of each test case contains four integers n, m, i, j (1≤n,m≤109, 1≤i≤n, 1≤j≤m) — the dimensions of the room, and the cell at which Anton is currently standing.

Output
For each test case, print four integers x1, y1, x2, y2 (1≤x1,x2≤n, 1≤y1,y2≤m) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates (x1,y1) and (x2,y2).

If there are multiple answers, you may print any.

Example
inputCopy
7
2 3 1 1
4 4 1 2
3 5 2 2
5 1 2 1
3 1 3 1
1 1 1 1
1000000000 1000000000 1000000000 50
outputCopy
1 2 2 3
4 1 4 4
3 1 1 5
5 1 1 1
1 1 2 1
1 1 1 1
50 1 1 1000000000
Note
Here is a visualization of the first test case.

我的思路:

根据几何思想,那个yo-yo master只能放到矩形的四个端点,那么,可以选择的只有6种可能,枚举即可

我的错误,爆int了

明明测试案例里面的最后一个就爆int了,我太垃圾了。在计算路径长度的时候,需要算三个边长的和。
ac代码:

#include <bits/stdc++.h>
using namespace std;
struct dian{
    int x;
    int y;
    //int len;
}s[4];
long long longway(int a,int b,int i, int j)
{
    return abs(a-i)+abs(b-j);
}
int main() {
    //std::cout << "Hello, World!" << std::endl;
    int t,m,n,i,j,ans;
    cin >> t;
    vector<long long > le(6);
    while(t--)
    {
        cin>>m>>n>>i>>j;
        s[0].x=1;s[0].y =1;
        s[1].x = 1;s[1].y = n;
        s[2].x = m;s[2].y = n;
        s[3].x = m;s[3].y = 1;
        for (int k = 0; k < 4; ++k) {
            le[k] = longway(s[k].x,s[k].y,i,j)+ longway(s[(k+1)%4].x,s[(k+1)%4].y,i,j)+longway(s[k].x,s[k].y,s[(k+1)%4].x,s[(k+1)%4].y);
        }
        le[4] = longway(s[0].x,s[0].y,i,j)+ longway(s[2].x,s[2].y,i,j)+ longway(s[0].x,s[0].y,s[2].x,s[2].y);
        le[5] = longway(s[1].x,s[1].y,i,j)+ longway(s[3].x,s[3].y,i,j)+ longway(s[1].x,s[1].y,s[3].x,s[3].y);
        ans = 0;
        for (int k = 1; k < 6; ++k) {
            if(le[k]>=le[ans]) ans = k;
        }
        if(ans <4)
            cout<<s[ans].x<< ' '<<s[ans].y<<' '<<s[(ans+1)%4].x<< ' '<<s[(ans+1)%4].y<< ' '<<endl;
        else if(ans == 4) cout<<s[0].x<< ' '<<s[0].y<< ' '<<s[2].x<< ' '<<s[2].y<<endl;
        else cout<<s[1].x<< ' '<<s[1].y<< ' '<<s[3].x<< ' '<<s[3].y<<endl;
    }
    return 0;
}

在思考一下发现

其实对角线两个点的路径长度是最长的只需要直接输出即可

#include "bits/stdc++.h"
using namespace std;
int main ()
{
    int T,n,m,i,j ;
    cin >> T;
    while(T--)
    {
        cin>>m>>n>>i>>j;
        cout <<'1' <<' '<<'1'<<' '<<m<<' '<<n<<endl;
 
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夭辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值