[贪心] UOJ136. [UER #3]开学前的作文

水水的题,贪心尽量走对角线,注意特判就好了...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
int _test,n,m;
int main(){
freopen("uoj136.in","r",stdin);
freopen("uoj136.out","w",stdout);
scanf("%d",&_test);
while(_test--){
scanf("%d%d",&n,&m); n--; m--;
if(n>m) swap(n,m);
if(n<=1){
if(m<=2) printf("%d\n",n+m); else printf("%d\n",n+2+(m-2+1)/2);
} else{
m-=n;
if(m==0) printf("%d\n",n+1);
else printf("%d\n",n+1+1+(m-1+1)/2);
}
}
return 0;
}