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. stark组件之创建

    stark组件之需求 仿照Django中的admin , 开发了自己的stark组件,实现类似数据库客户端的功能,对数据进行增删改查 . stark之创建 1.在项目中 创建stark应用,app01 ...

  2. grep常用选项记录

    grep: 一.常用选项:    -i 不区分大小写针对单个字符    -v 显示不包括查找字符的所有行    -o 只打印出匹配到的字符    -c 显示有多少行被匹配到    -e 可以使用多个表 ...

  3. 事务(JDBC、Spring)

    如果不用spring管理事务,我们自己写代码来操作事务.那么这个代码怎么写要看底层怎么访问数据库了. 当采用原生JDBC访问数据库时,操作事务需要使用java.sql.Connection的API.开 ...

  4. restful风格下的ajax跨域问题的解决

    Ajax跨域请求时,如果设置Header的ContentType为application/json,会分两次发送请求一次先发送Method为OPTIONS的请求到服务器,这个请求会询问服务器支持哪些请 ...

  5. inventor怎样卸载干净

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

  6. Neutron命令测试2

    /etc/network/interfaces auto loiface lo inet loopback auto eth0iface eth0 inet manualup ifconfig $IF ...

  7. Oozie安装部署

    不多说,直接上干货! 首先,大家先去看我这篇博客.对于Oozie的安装有一个全新的认识. Oozie安装的说明 我这里呢,本篇博文定位于手动来安装Oozie,同时避免Apache版本的繁琐编译安装,直 ...

  8. java连接数据库驱动代码综合共享

    1.Oracle8/8i/9i数据库(thin模式)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();S ...

  9. SWIG 和 Python——c/c++与脚本交互

    C 和 C++ 被公认为(理当如此)创建高性能代码的首选平台.对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface ...

  10. HDU 5384——Danganronpa——————【AC自动机】

    Danganronpa Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...