zoukankan      html  css  js  c++  java
  • cf478B Random Teams

    B. Random Teams
    time limit per test 1 second
    memory limit per test 256 megabytes
    input standard input
    output standard output

    n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

    Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

    Input

    The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

    Output

    The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

    Sample test(s)
    input
    5 1
    
    output
    10 10
    
    input
    3 2
    
    output
    1 1
    
    input
    6 3
    
    output
    3 6
    
    Note

    In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.

    In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.

    In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

    n个人分到m组里,每一组对于答案的贡献是人数排列组合,就是n*(n-1)/2。求最大值和最小值

    显然前面取m-1组的1最后一组最大的方案是答案最大

    平均分的方案是答案最小

     1 #include<cstdio>  
     2 #include<iostream>  
     3 #include<cstring>  
     4 #include<cstdlib>  
     5 #include<algorithm>  
     6 #include<cmath>  
     7 #include<queue>  
     8 #include<deque>  
     9 #include<set>  
    10 #include<map>  
    11 #include<ctime>  
    12 #define LL long long  
    13 #define inf 0x7ffffff  
    14 #define pa pair<int,int>  
    15 #define pi 3.1415926535897932384626433832795028841971  
    16 using namespace std;  
    17 inline LL read()  
    18 {  
    19     LL x=0,f=1;char ch=getchar();  
    20     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  
    21     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  
    22     return x*f;  
    23 }  
    24 LL a,b,c,d,e;  
    25 int main()  
    26 {  
    27     a=read();b=read();  
    28     c=(a-b+1)*(a-b)/2;  
    29     d=(a-b*(a/b));  
    30     e=(d)*(a/b+1)*(a/b)/2+(b-d)*(a/b)*(a/b-1)/2;  
    31     printf("%lld %lld
    ",e,c);  
    32 }  
    cf478B
    ——by zhber,转载请注明来源
  • 相关阅读:
    解决Unsupported major.minor version 51.0问题的感悟
    python 自己实现for循环:
    去除(UTF8)格式文本中的Bom
    python range与xrange
    Permission denied: make_sock: could not bind to address处理
    This Android SDK requires Android Developer Toolkit version 20.0.0 or above
    centos下postgresql的安装与配置 20101217 12:39:15
    android软键盘 android:windowSoftInputMode
    android 代码实现安装卸载apk
    Android有效解决加载大图片时内存溢出的问题
  • 原文地址:https://www.cnblogs.com/zhber/p/4055125.html
Copyright © 2011-2022 走看看