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. tarjan算法,一个关于 图的联通性的神奇算法

    一.算法简介 Tarjan 算法一种由Robert Tarjan提出的求解有向图强连通分量的算法,它能做到线性时间的复杂度. 我们定义: 如果两个顶点可以相互通达,则称两个顶点强连通(strongly ...

  2. Codeforces Round #335 (Div. 2) A

    A. Magic Spheres time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. Realm数据库的使用

    https://github.com/lipanquan/Realm/tree/master

  4. my14_mysql指定时间恢复之模拟从库

    场景 *********************************线上库数据误删除,存在几天前的一份全备数据,现需要恢复这些误删除的数据本例方案:在另外一台服务器上,恢复全备,搭建binlog ...

  5. 将个人博客与github关联

    目录 将个人博客与github关联 将个人博客与github关联 #基于svg <a href="https://github.com/chatlotte" class=&q ...

  6. =与==、&与&&、| 与 || 的区别

    =与== =属于赋值运算符,将右侧的值赋给左侧的变量名称 ==属于关系运算符,判断左右两边值是否相等,结果为boolean类型 &与&& &是逻辑与,&& ...

  7. 搜索提示(search suggest)文献阅读

    Learning to Personalize Query Auto-Completion 样本 正例用用户的sug点击,其余是负例 特征 用户历史特征: query历史频次,候选和用户历史输入的ng ...

  8. Mac 系统变量

    vim .bash_profile ========================= MAVEN_HOME = < ... > export MAVEN_HOME =========== ...

  9. [转]how can I change default errormessage for invalid price

    本文转自:http://forums.asp.net/t/1598262.aspx?how+can+I+change+default+errormessage+for+invalid+price I ...

  10. java多线程之原子变量

    看链接博客:http://blog.csdn.net/u011116672/article/details/51068828