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. Angular组件生命周期——生命周期钩子

    生命周期钩子介绍: 1.ngOnChange:响应组件输入值发生变化时触发的事件. 2.ngOnInit:用于数据绑定输入属性之后初始化组件,在第一次ngOnChange之后被调用. a. 组件构造后 ...

  2. GIL 线程池 进程池 同步 异步 阻塞 非阻塞

    1.GIL 是一个全局解释器锁,是一种互斥锁 为什么需要GIL锁:因为一个python.exe进程中只有一份解释器,如果这个进程开启了多个线程都要执行代码 多线程之间要竞争解释器,一旦竞争就有可能出现 ...

  3. Should I buy Auro OtoSys IM600 or Obdstar X300 DP?

    Auro OtoSys IM600 and Obdstar X300 DP – What’s the difference & Which better? This is for those ...

  4. c语言中有关0和1的运算问题

    /*有关0和1 的总结 最近做题总是混淆0 和 1 对于/ 和 %运算时候的结果怎么算 所以就上机试验了一番 结论: c语言中,0/任何数都为0 0%任何数都为0 1/任何数都为0 1%任何数都余1 ...

  5. py---------常用模块2

    一.hashilb 模块 python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固 ...

  6. Java日志组件1---Jdk自带Logger(java.util.logging.Logger)

    最近在看日志的一些东西,发现利用JDK自带的log也可以简单的实现日志的输出,将日志写入文件的过程记录如下: 1.新建LogUtil.Java( 里面写了几个静态方法,为log设置等级.添加log控制 ...

  7. kafka与zookeeper读写分析

    kafka的读写都通过leader完成,而zookeeper只有写要通过leader而读可以通过任意follower,我觉得造成这种差异的原因还是在于使用场景. kafka的设计目标是实现一个高吞吐的 ...

  8. Mybatis学习笔记6 - #{}和${}

    #{}:可以获取map中的值或者pojo对象属性的值.${}:可以获取map中的值或者pojo对象属性的值. 区别: #{}:是以预编译的形式,将参数设置到sql语句中:PreparedStateme ...

  9. maya2017安装失败如何卸载重装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  10. CentOS 搭建Redis4 环境

    下载 wget http://download.redis.io/releases/redis-4.0.10.tar.gz   安装步骤 tar xvf redis-4.0.10.tar.gz mak ...