1929. Teddybears are not for Everyone (Timus) (combination+reading questions)

http://acm.timus.ru/problem.aspx?space=1&num=1929 

combination problems. 排列组合问题。

According to the problems, it is assumed that Holden is chosen and there are two more open positions. And based on this combination, constraints are needed to be satisfied that there must be at least one Teddyhater in each group.  Totally

n: people, m: haters and n%3==0

k = n%3

case 1: m < k: impossible 0

case 2: m == k

            Holden is a hater: (Holden)(non-hater)(non-hater) = (n-m)(n-m-1)/2

            Holden is not a hater: (Holden)(Hater)(non-hater) = (m)(n-m-1)

case 3: m == k+1 : one more haters

            Holden is hater: (Holden)(non-hater)(non-hater) + (Holden)(hater)(non-hater) 

            Holden is not a hater: (Holden)(Hater)(non-hater) + (Holden)(Hater)(hater)

case 4: else : two more or three more

            Holden is hater: (Holden)(non-hater)(non-hater) + (Holden)(hater)(non-hater) + (Holden)(hater)(hater) = (Holden)(others)(others)

            Holden is not a hater: (Holden)(Hater)(non-hater) + (Holden)(Hater)(hater) 

import java.util.Scanner;

public class timus1929 {
    //https://github.com/fanofxiaofeng/timus/blob/master/1929/main.py -- reference
    //http://acm.timus.ru/problem.aspx?space=1&num=1929 -- problem
    // Holden is here and there two more spots left
    public static void main(String[] args) {
        Scanner in  =new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = n/3; //groups
        int tag = 0;//Hole is not haters
        for(int i = 0; i<m; i++){
            if(in.nextInt()==1)
                tag = 1;
        }
        int res = 1;
        if(m<k){
            System.out.println(0);
            return;
        }
        if(tag==0){
            if(m==k) res = m*(n-m-1);
            //else res = m*(n-m-1) + m*(m-1)/2;
            else if(m==k+1) res = m*(n-m-1) + m*(m-1)/2;
            else res = (n-1)*(n-1-1)/2 - (n-m-1)*(n-m-2)/2;
        }else {//Holden is haters
            if(m==k) res = (n-k)*(n-k-1)/2;
            //else res = (n-m)*(n-m-1)/2 + (m-1)*(n-m);
            else if(m==k+1) res = (n-m)*(n-m-1)/2 + (m-1)*(n-m);
            else res = (n-m)*(n-m-1)/2 + (m-1)*(n-m) + (m-1)*(m-2)/2; //res = (n-1)*(n-1-1)/2;//1: Holden and// res = (n-m)*(n-m-1)/2 + (m-1)*(n-m) + (m-1)(m-2)/2
        }

        //int res = combination(4,0);
        System.out.println(res);
    }
}

 

It is hard to figure out the meaning of the problems

tai tm nan le!!!!

     

转载于:https://www.cnblogs.com/stiles/p/timus1929.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值