Desktop(模拟)2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest

Vasily is a college student who likes to keep everything in order. One of his hobbies is software. Yesterday he installed a new operating system Windows 999999. The key difference between the new system and Windows XP is that Windows 999999 has 999,999 pre-installed utilities and after the installation of the system, the desktop is absolutely empty. Vasily wants to place the maximum number of shortcuts to the utilities on his desktop. His computer screen is a grid sized h × w and the icons are squares sized 2 × 2. Icons must be positioned so that their corners match the borders of grid cells. They can also overlap each other, so the bottom icon will be partly covered by the top one. For comfort, Vasily decided that at least half of an icon (2 cells) must be visible; otherwise it would be hard to click on it. Now Vasily wants to know the maximum number of icons that can be placed on his desktop and the appropriate positioning pattern.

Limitations

1 ≤ h, w ≤ 500

Input

The first line in the input file contains two integer numbers h and w , representing the height and the width of Vasily’s computer screen.

Output

The first line in the output file must contain the number N – the maximum number of icons that can be fitted on Vasily’s desktop considering the conditions listed above. If N>0, the next N lines must contain pairs of numbers representing the coordinates of the upper right corners of the icons (line number and column number). The icons will be placed in the same order as they are listed, so each subsequent icon might lap over some of the previously listed icons.

Examples

Input.txt

2 4

Output.txt

3

1 1

1 2

1 3

 

模拟题,Wa了十四边,最后才知道,坐标是从下往上从0开始的

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     freopen("input.txt", "r", stdin);
 6     freopen("output.txt", "w", stdout);
 7     int n, m, i, j;
 8     scanf("%d %d", &n, &m);
 9     if(n<2||m<2)
10     {
11         printf("0\n");
12     }
13     else
14     {
15         printf("%d\n", n*m/2-1);
16         if(n%2==1)
17         {
18             for(i=m-1; i-1>=0; i-=2)
19             {
20                 printf("%d %d\n", 1, i);
21             }
22         }
23         for(i=n-1; i-1>=0; i-=2)
24         {
25             for(j=m-1; j-2>=0; j--)
26             {
27                 printf("%d %d\n", i, j);
28             }
29         }
30 
31         for(i=n-1; i-1>=0; i--)
32         {
33             if(i-2<0&&n%2==1) break;
34             printf("%d %d\n", i, 1);
35         }
36 
37     }
38     return 0;
39 }

 

转载于:https://www.cnblogs.com/0xiaoyu/p/11341800.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值