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.
每个源点选择一个屏幕进行连线,如下图:
这样会剩下(M-K)个屏幕在链接的时候一定会链接不同的源点,并且链接的源点一定是K个,因为在显示的时候是要求选择K个屏幕同时出现不同的颜色,如果链接的源点少于K个就会出现重复颜色。如下图:
最后,可以得到一个公式: 需要的连线数目=K+(M-K)* K , 整理得K*(M+1)-K*K 需要注意一下M,K的范围,需要用long long存,要不就是WA…..Orz
#include<stdio.h>
int main(void)
{
long long M, K;
while (scanf("%lld%lld", &M, &K) != EOF)
{
printf("%lld\n", K*(M + 1) - K*K);
}
return 0;
}