[智力题]1395: Planting Tree

Description

Novel-Supertv Digital TV Technology Co., Ltd is one of the leading digital TV technology solution providers in China. Novel-Supertv offers customized solutions for cable, satellite, terrestrial, IPTV, and handset TV networks. We  often hold some competitions, games and other activities, like playing ping pang ball, basket ball, climbing mounting, live battle CS  and so on.Last year we organized a planting tree activity, a colleague think out a  very interesting question . The question is:
There are N (N>=2) trees, you can plant into several lines. If a line have and only have M (2<=M<=N) trees, we called it “M trees line”. We wonder the maximum lines of “M trees line” that it can be planted with the N trees. Now, can you make a program and tell us the answer?
For example: 

Input
The input contains several lines. Each line contains two integer N and M separating with several blank characters . (2<=N<=10, 2<=M<=N).

Output

For each input line, you should output a line contains the maximum lines of M trees line that it can be planted.


Sample Input

3 2

4 2

4 3

Sample Output
3
6
1
  
  
给定N棵树,每行只能种M棵(不能多也不能少),最多能种多少行,允许一棵树同时属于几行。
智力题,数据范围不大,可直接打表。除了打表以外我还没有找出可以做的方法……

2

3

4

5

6

7

8

9

2

1

0

0

0

0

0

0

0

0

3

3

1

0

0

0

0

0

0

0

4

6

1

1

0

0

0

0

0

0

5

10

2

1

1

0

0

0

0

0

6

15

4

1

1

1

0

0

0

0

7

21

6

2

1

1

1

0

0

0

8

28

7

2

1

1

1

1

0

0

9

36

10

3

2

1

1

1

1

0

10

45

12

5

2

1

1

1

1

1

其中几个难打的地方画图如下:有些真的不会想到竟然会是这样画的……
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
using namespace std;

int mat[9][9]={   1, 3, 6,10,15,21,28,36,45,
                 -1, 1, 1, 2, 4, 6, 7,10,12,
                 -1,-1, 1, 1, 1, 2, 2, 3, 5,
                 -1,-1,-1, 1, 1, 1, 1, 2, 2,
                 -1,-1,-1,-1, 1, 1, 1, 1, 1,
                 -1,-1,-1,-1,-1, 1, 1, 1, 1,
                 -1,-1,-1,-1,-1,-1, 1, 1, 1,
                 -1,-1,-1,-1,-1,-1,-1, 1, 1,
                 -1,-1,-1,-1,-1,-1,-1,-1, 1
                    };
int main()
{
    int M,N;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        printf("%d\n",mat[M-2][N-2]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值