ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1.22训练赛 --ac2

2020-01-11 13:52:24  阅读:445  来源: 互联网

标签:point move number Mikhail ac2 训练赛 go 1.22 moves


Final standings Solved: 2 out of 7 ac:A题水题  b题思维题 b题:
B. Diagonal Walking v.2
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mikhail walks on a Cartesian plane. He starts at the point (0,0)
, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)

, he can go to any of the following points in one move:

    (1,0)

;
(1,1)
;
(0,1)
;
(−1,1)
;
(−1,0)
;
(−1,−1)
;
(0,−1)
;
(1,−1)

    . 

If Mikhail goes from the point (x1,y1)
to the point (x2,y2) in one move, and x1≠x2 and y1≠y2

, then such a move is called a diagonal move.

Mikhail has q
queries. For the i-th query Mikhail's target is to go to the point (ni,mi) from the point (0,0) in exactly ki moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point (0,0) to the point (ni,mi) in ki

moves.

Note that Mikhail can visit any point any number of times (even the destination point!).
Input

The first line of the input contains one integer q
(1≤q≤104

) — the number of queries.

Then q
lines follow. The i-th of these q lines contains three integers ni, mi and ki (1≤ni,mi,ki≤1018) — x-coordinate of the destination point of the query, y

-coordinate of the destination point of the query and the number of moves in the query, correspondingly.
Output

Print q
integers. The i-th integer should be equal to -1 if Mikhail cannot go from the point (0,0) to the point (ni,mi) in exactly ki moves described above. Otherwise the i

-th integer should be equal to the the maximum number of diagonal moves among all possible movements.
Example
Input
Copy

3
2 2 3
4 3 7
10 1 9

Output
Copy

1
6
-1

Note

One of the possible answers to the first test case: (0,0)→(1,0)→(1,1)→(2,2)

.

One of the possible answers to the second test case: (0,0)→(0,1)→(1,2)→(0,3)→(1,4)→(2,3)→(3,2)→(4,3)

.

In the third test case Mikhail cannot reach the point (10,1)
in 9 moves.

大概就是从(0,0)可以走直线可以走斜线,给定步数k,问能否k步正好到达终点,可以的话输出最多的斜线步数 。

在纸上乱画,发现可以把坐标系画成类似楷书格子的横竖斜交叉的格子

发现如果重点在斜线交叉内,在min(xd,yd)之步定可以到终点,且可以绕圈增步数,每次可增2步

然后k的大小奇偶判断

不再在写交叉内的话化未知为已知问题,即在k-1步内到达(x-1,y)或(y,x-1)

在同第一部判断

中间有的情况可以简化合并

#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    long long n,m,k,a,b,kmin;
    while(t--){
        scanf("%lld%lld%lld",&n,&m,&k);
        if(n%2==m%2){
            kmin=max(n,m);
            if(k<kmin)printf("-1\n");
            else if(k%2==kmin%2)printf("%lld\n",k);
            else printf("%lld\n",k-);
        }
        else{
            kmin=max(n-1,m-1);
            if(k-1<kmin)printf("-1\n");
            else printf("%lld\n",k-1);
        }
    } 
    return 0;
}

 

标签:point,move,number,Mikhail,ac2,训练赛,go,1.22,moves
来源: https://www.cnblogs.com/-ifrush/p/10302813.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有