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)

  1. import java.util.Scanner;
  2.  
  3. public class timus1929 {
  4. //https://github.com/fanofxiaofeng/timus/blob/master/1929/main.py -- reference
  5. //http://acm.timus.ru/problem.aspx?space=1&num=1929 -- problem
  6. // Holden is here and there two more spots left
  7. public static void main(String[] args) {
  8. Scanner in =new Scanner(System.in);
  9. int n = in.nextInt();
  10. int m = in.nextInt();
  11. int k = n/3; //groups
  12. int tag = 0;//Hole is not haters
  13. for(int i = 0; i<m; i++){
  14. if(in.nextInt()==1)
  15. tag = 1;
  16. }
  17. int res = 1;
  18. if(m<k){
  19. System.out.println(0);
  20. return;
  21. }
  22. if(tag==0){
  23. if(m==k) res = m*(n-m-1);
  24. //else res = m*(n-m-1) + m*(m-1)/2;
  25. else if(m==k+1) res = m*(n-m-1) + m*(m-1)/2;
  26. else res = (n-1)*(n-1-1)/2 - (n-m-1)*(n-m-2)/2;
  27. }else {//Holden is haters
  28. if(m==k) res = (n-k)*(n-k-1)/2;
  29. //else res = (n-m)*(n-m-1)/2 + (m-1)*(n-m);
  30. else if(m==k+1) res = (n-m)*(n-m-1)/2 + (m-1)*(n-m);
  31. 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
  32. }
  33.  
  34. //int res = combination(4,0);
  35. System.out.println(res);
  36. }
  37. }

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. day_06 再谈编码

    1. 小数据池(常量池) 1.id() 通过id()查询一个变量在内存中的地址 2.is和== 1.is 判断左右两端内存地址是否一致,如果返回值是TRUE,则可以判断这两个变量值是同一对象 2.== ...

  2. 统计Metric

    package com.example.mail; import org.apache.storm.Config; import org.apache.storm.LocalCluster; impo ...

  3. 10.Spring集成一

    1.Email 电子邮件工作原理: 邮件发送方通过邮件发送客户端把邮件发送到发送方的邮件服务器,在发送的过程中需要用到SMTP协议发送方的邮件服务器把邮件发送到接收方的邮件服务器,使用的协议也是SMT ...

  4. 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 ...

  5. Vue.js-----轻量高效的MVVM框架(十、父子组件通信)

    #1.父链 html: <h3>#父链</h3> <div> <div>子组件可以用 this.$parent 访问它的父组件.根实例的后代可以用 th ...

  6. 转发 django 初探

    https://www.cnblogs.com/franknihao/p/7682914.html https://blog.csdn.net/tang_jin2015/article/details ...

  7. Windows Server 2008下的FTP服务器设置

    今天刚在新服务器上部署好Windows Server 2008,同时安装好了SQL,基本上还算顺利.没想到在设置FTP服务器的时候遇到了麻烦.按照以往的经验,安装好Serv-U以后,同时在防火墙设置里 ...

  8. 织梦更新列表页提示Fatal error: Call to a member function GetInnerText() on a non-object 解决方法

    今天在做一个站时用到了自定义模型,遇到了些问题,在更新列表页时提示: Fatal error: Call to a member function GetInnerText() on a non-ob ...

  9. Python四大神兽(迭代器&生成器&闭包&装饰器)

    一.迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式.. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不 ...

  10. MVC execl 导入导出

    MVC execl 导入导出 <input id="xls" name="xls" type="file" style="w ...