1929. Teddybears are not for Everyone (Timus) (combination+reading questions)
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)的更多相关文章
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- [LeetCode] Combination Sum III 组合之和之三
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- [LeetCode] Combination Sum II 组合之和之二
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- [LeetCode] Combination Sum 组合之和
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- 55. 2种方法求字符串的组合[string combination]
[本文链接] http://www.cnblogs.com/hellogiser/p/string-combination.html [题目] 题目:输入一个字符串,输出该字符串中字符的所有组合.举个 ...
- 377. Combination Sum IV
问题 Given an integer array with all positive numbers and no duplicates, find the number of possible c ...
- Leetcode 377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- Leetcode 216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Leetcode 40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
随机推荐
- Ansible故障
常见问题一: [root@m01 ~]# ansible -k 172.16.1.51 -m ping SSH password: [WARNING]: No hosts matched, noth ...
- Go语言基础环境配置(windows)
一.基础软件包安装 需要安装go环境包.git.IDE(VScode),安装包见下图: 1.1 安装go windows环境直接双击安装包安装即可,在cmd窗口输入go,结果如下图所示即表示安装成功: ...
- CROSS APPLY和 OUTER APPLY 区别详解
SQL Server 2005 新增 cross apply 和 outer apply 联接语句,增加这两个东东有啥作用呢? 我们知道有个 SQL Server 2000 中有个 cross joi ...
- js中url有中文的转码方法
转载:https://www.cnblogs.com/chiangfai/p/6073000.html
- java——arr == null || arr.length == 0
这两者是不同的: arr == null; int[] arr = null; arr.length == 0; int[] arr =new int[0];
- my.资料收集_20170912
1.终于摸索出平民单开赚钱方法了!![梦幻西游手游吧]_百度贴吧.html http://tieba.baidu.com/p/5323468885?see_lz=1 1.http://tieba.ba ...
- 转 PyCharm 进行调试 以及怎么熟悉一个已经成熟的项目的代码和断点 以及 jetBrains pycharm快捷键
https://blog.csdn.net/guider2334/rss/list Ctrl + Q 现实document视图,查看选择元素的详细信息 (重要) Ctrl + Alt + ...
- SpringBoot---数据缓存(未完待续)
1.概述 1.1 在Spring中使用缓存的关键是配置CacheManager,而SpringBoot为我们自动配置了多个CacheManager的实现: 1.2 SpringBoot的CacheMa ...
- java多线程(三)
1.1什么的多线程的安全问题? 多个线程对共享资源进行访问时,引起共享资源不一致的问题. 1.2一般解决多线程安全问题的解决方案有哪些? 1.2.1 同步方法 public synchroniz ...
- RTT之内存管理及异常中断
内存管理分静态内存管理和动态内存管理(根据大小又分2种) 静态内存管理:创建.删除.初始化.解绑.申请和释放.初始化内存池是属于静态内存管理,与创建内存池不同的是,此处内存池对象所使用的内存空间是由用 ...