思路:当m > k时输出-1(设m是较大的数),当m-n是奇数时有一步不能走对角线所以k--,当走对角线可以直接到达终点,如果剩余的步数是奇数则有两步不能走对角线所以k - 2。(画图观察规律)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int q;
scanf("%d",&q);
while(q--)
{
ll n,m,k;
scanf("%lld%lld%lld",&n,&m,&k);
if(n>m)
swap(n,m);
if(k<m)
{
printf("-1\n");
continue;
}
ll res;
if( (m-n)%2==0 )
{
if(k%2==m%2)
{
printf("%lld\n",k);
}
else
{
printf("%lld\n",k-2);
}
}
else if( (m-n)%2==1 )
{
if(k==m)
{
printf("%lld\n",k-1);
continue;
}
else if(k>m)
{
ll sheng=k-n;
ll cha=m-n;
if(sheng%2==cha%2)
{
if(cha%2==0)
{
res=k;
}
else if(cha%2==1)
{
res=k-1;
}
}
else
{
if(cha%2==1&&sheng%2==0)
{
res=k-1;
}
else if(cha%2==0&&sheng%2==1)
{
res=k-2;
}
}
printf("%lld\n",res);
continue;
}
}
}
}