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!!!!

1929. Teddybears are not for Everyone (Timus) (combination+reading questions)的更多相关文章

  1. [LeetCode] Combination Sum IV 组合之和之四

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  2. [LeetCode] Combination Sum III 组合之和之三

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  3. [LeetCode] Combination Sum II 组合之和之二

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  4. [LeetCode] Combination Sum 组合之和

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  5. 55. 2种方法求字符串的组合[string combination]

    [本文链接] http://www.cnblogs.com/hellogiser/p/string-combination.html [题目] 题目:输入一个字符串,输出该字符串中字符的所有组合.举个 ...

  6. 377. Combination Sum IV

    问题 Given an integer array with all positive numbers and no duplicates, find the number of possible c ...

  7. Leetcode 377. Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  8. Leetcode 216. Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  9. Leetcode 40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

随机推荐

  1. Jury Jeopardy (这是一道单纯的模拟题)

    Description What would a programming contest be without a problem featuring an ASCII-maze? Do not de ...

  2. setlocal 本地变量详解

    命令 setlocal (开启本地变量)  endlocal (结束本地变量) 很多新手不理解这句话是什么意思,在批处理中有什么作用. 其实在批处理中 setlocal 作用很大,配合 endloca ...

  3. 查询linux服务器有哪些IP在连接

    查询linux服务器有哪些IP在连接 netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n 查看linux的 ...

  4. Linux磁盘分区管理

    1.分区步骤          fdisk -l                                  查看系统中的磁盘 fdisk /dev/vdb                   ...

  5. 时间复杂度——cin加速器

    static auto _=[]() { ios::sync_with_stdio(false); cin.tie(); ; }(); 代码简析:   cin,cout效率低是因为他们要将输入输出的数 ...

  6. Android studio配置push commits

    最近更新了Android studio到3.2.1最新版本 我们代码用的是Git来管理,提交代码用Android studio自带,发现最新版本的push commits不能保存 把默认的develo ...

  7. python 横向比较最大值 贴标签

    df['dfda']=pd.Series(df[['a','b','v']].idxmax(axis=1),index=df.index)#横向比较最大值并返回列名,比循环快N倍

  8. Java基础07-随机数

    第一种方法:导入java.util.Random; import java.util.Random; public class Test1{ public static void main(Strin ...

  9. 封装RateLimiter 令牌桶算法

    自定义注解封装RateLimiter.实例: @RequestMapping("/myOrder") @ExtRateLimiter(value = 10.0, timeOut = ...

  10. 如何有效防止DEDE织梦系统被挂木马安全设置(仅供参考)

    尊敬的客户,您好!     感谢广大客户对我司工作的信任和支持!      我司在最近的一个多月内陆续发现多起因 DedeCMS 安全漏洞造成网站被上传恶意脚本的事件,入侵者可利用恶意脚本对外发送大量 ...