HDU - cable cable cable(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6195
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description

Connecting the display screen and signal sources which produce different color signals by cables, then the display screen can show the color of the signal source.Notice that every signal source can only send signals to one display screen each time. 
Now you have M display screens and K different signal sources(K \leq M \leq 2^{32}-1). Select K display screens from M display screens, how many cables are needed at least so that **any** K display screens you select can show exactly K different colors.

Input

Multiple cases (no more than 100), for each test case:
there is one line contains two integers M and K.

Output

Output the minimum number of cables N.

Sample Input

3 2
20 15

Sample Output

4
90

Hint

As the picture is shown, when you select M1 and M2, M1 show the color of K1, and M2 show the color of K2. When you select M3 and M2, M2 show the color of K1 and M3 show the color of K2. When you select M1 and M3, M1 show the color of K1.

Problem solving report:

Description: 有m个显示器和k个信号源,每个显示器如果通过电缆连接一个信号源就会发某种光,要求是在m个显示器中任意选择k个都会显示k种不同的颜色,问最少需要多少电缆?
Problem solving: 假设我们已经连好k-1个,那么要想满足要求,则剩余的那些m-(k-1)个显示屏都要与最后那个信号源连接,所以每个信号源至少要连接m-(k-1)个显示屏,共有k个显示屏,所以共需要k*(m-(k-1))个光缆。

Accepted Code:

/* 
 * @Author: lzyws739307453 
 * @Language: C++ 
 */
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long m, k;
    while (~scanf("%lld%lld", &m, &k))
        printf("%lld\n", (m - (k - 1)) * k);
    return 0;
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 代码科技 设计师:Amelia_0503 返回首页