HDU - 6195 cable cable cable

题意:如下图,有K个光源,一个光源可同时照射一个显示屏,问从M个显示屏中任选K个,可以使每个显示屏都被不同光源照亮最少需要多少连接电缆。

分析:画图分析可知

1、选1~K个显示屏和选M-K+1~M个显示屏对于所有灯泡来说是两个极限照射范围

2、比如,对于第一个灯泡,选1~K个显示屏他要照到第一个显示屏,选M-K+1~M个显示屏他要照到第M-K+1个显示屏,所以他的照射范围是M-K+1,有K个灯泡,所以K * (M - K + 1)。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
    LL M, K;
    while(scanf("%lld%lld", &M, &K) == 2){
        printf("%lld\n", K * (M - K + 1));
    }
    return 0;
}

  

posted @ 2017-09-13 20:18  Somnuspoppy  阅读(261)  评论(0编辑  收藏  举报