题面:https://www.luogu.org/problemnew/show/P4431
为了方便,我们先举个例子:\(n=4,m=7\)的情况。
如图:
(橙色圆圈为转向点。)显然答案是6。
我们发现:转折点都在短边上。
还有,转折点的分布规律还有(如图):
(请将上图的矩形沿中心对称一下。)
易知转折点共有 \(2(m-1)\) 个 。
同理,若\(n\le m\)的话那答案就是 \(2(n-1)\) 个。
综上,答案 \(=(\min (n,m)-1)\times 2\)
\(Code:\)
#include<cstdio>
using namespace std;
int k,n,m;
inline int min(int x,int y){return (x<y)?x:y;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
inline void write(int x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');return;}
int main()
{
k=read();
while(k--)
write(2*(min(read(),read())-1)),putchar('\n');
return 0;
}