• 网络赛:2017 ACM/ICPC Asia Regional Shenyang Online

  • 题目来源:cable cable cable

  • 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≤M≤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.

  • 题目分析:对于每个测试样例给两个整数,分别是M个display screens,K个different signal sources,(K≤M≤2^32−1),从M个screens中选出K个screens,在源头和屏幕之间连线,使得这K个屏幕可以显示出不同的K中颜色。
    连线只存在源头和屏幕之间。

  • 我的思路:
    首先,对于K个源点,先对K个屏幕连一条线,以K=3,M=4为例子:

    每个源点选择一个屏幕进行连线,如下图:

    这样会剩下(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;
}

Problem 1002-2017 ACM/ICPC Asia Regional Shenyang Online的更多相关文章

  1. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  2. 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction

    Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...

  3. 2017 ACM/ICPC Asia Regional Shenyang Online cable cable cable

    Problem Description Connecting the display screen and signal sources which produce different color s ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. 2017 ACM/ICPC Asia Regional Shenyang Online 记录

    这场比赛全程心态爆炸…… 开场脑子秀逗签到题WA了一发.之后0贡献. 前期状态全无 H题想复杂了,写了好久样例过不去. 然后这题还是队友过的…… 后期心态炸裂,A题后缀数组理解不深,无法特判k = 1 ...

  6. 2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198【矩阵快速幂】

    Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, ...

  7. 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)

    HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...

  8. HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

    题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...

  9. HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)

    思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定.   快速幂入门第一题QAQ #include <stdio.h> #include <stdlib.h& ...

  10. 2017 ACM/ICPC Asia Regional Shenyang Online array array array

    2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...

随机推荐

  1. [转]关于Jquery的DataTables里TableTools的应用

    本文转自:http://147068307.iteye.com/blog/1700516 最近在产品中使用了TableTools这个工具,主要用来实现导出和复制功能. 但是在实际的运用中出现了以下相关 ...

  2. nodejs --- crypto实现加密(转)

    crypto实现加密 本文转自:http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/0 ...

  3. Ubuntu16.04搭建深度学习框架——TensorFlow

    TensorFlow是一个采用数据流图(data flow graphs),用于数值计算的开源软件库,说白了,就是一个库. 小编自己在Ubuntu搭建了深度学习框架TensorFlow,感觉挺简单,现 ...

  4. stm32 独立看门狗学习

    STM32F10xxx内置两个看门狗,提供了更高的安全性.时间的精确性和使用的灵活性.两个看门狗设备(独立看门狗和窗口看门狗)可用来检测和解决由软件错误引起的故障. 独立看门狗(IWDG)由专用的低速 ...

  5. 快速学习 Python 数据分析包 之 pandas

    最近在看时间序列分析的一些东西,中间普遍用到一个叫pandas的包,因此单独拿出时间来进行学习. 参见 pandas 官方文档 http://pandas.pydata.org/pandas-docs ...

  6. Java学习第十六天

    1:List的子类(掌握) (1)List的子类特点 ArrayList: 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector: 底层数据结构是数组,查询快,增删慢 线程安全,效率低 ...

  7. javascript 数组方法拼接html标签

    var htmls = new Array(); htmls.push("<tr class='otherinfotr'>");htmls.push("< ...

  8. React API

    组件 API setState 合并 nextState 和当前 state. 这是在事件处理函数中和请求回调函数中触发 UI 更新的主要方法. 另外,也支持可选的回调函数,该函数在 setState ...

  9. (生产)animate.css 动画库

    官网:https://daneden.github.io/animate.css/ Animate.css是一个有趣的,跨浏览器的css3动画库 用法 首先引入animate css文件:    &l ...

  10. atom markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module

    atom编辑器markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module. You have to set th ...