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 ...
随机推荐
- day14 面向对象
. 面向对象和面向过程 .面向过程:核心是过程,是流水线 优缺点: .流程化,编写简单 .可扩展性差 .面向对象:核心是对象(对象:具有相同属性和动作的结合体) 优缺点: .可扩展行强 .复杂度高于面 ...
- Autel MaxiSYS Pro Diagnostic System
The Autel Maxisys Pro Diagnostic System is a complete OEM-level diagnostic system that enables the s ...
- python : No such file or directory
windows上写的python脚本,在linux上执行时报: No such file or directory 解决方法一# sed -i 's#\r##' mysqlchk.py 解决方法二脚本 ...
- 《mac的git安装手册-1》
<mac的git安装手册-1> 下载地址 https://git-scm.com/downloads 如果遇到上面这个问题打开系统偏好设置: OK,这样就能安装了
- Robot Framework 的安装和配置
Robot Framework 的安装和配置 在使用 RF(Rebot framework)的时候需要 Python 或 Jython 环境,具体可根据自己的需求来确定.本文以在有 Python 的环 ...
- 谨慎使用多线程中的fork 学习!!!!
前言 在单核时代,大家所编写的程序都是单进程/单线程程序.随着计算机硬件技术的发展,进入了多核时代后,为了降低响应时间,重复充分利用多核cpu的资源,使用多进程编程的手段逐渐被人们接受和掌握.然而因为 ...
- java高级篇
Method对象可以得到任何一个类的任何方法的定义(只需要传入方法的名字和参数即可) class Ming { private void speak() { System.out.println(&q ...
- 错误 chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’
修改 ./build/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make文件,删掉-Werror=address,然后重新make
- MATLAB线性回归方程与非线性回归方程的相关计算
每次比赛都需要查一下,这次直接总结到自己的博客中. 以这个为例子: 2.线性方程的相关计算 x=[1,2,3,4,5]';%参数矩阵 X=[ones(5,1),x];%产生一个5行一列的矩阵,后接x矩 ...
- LeetCode 455.分发饼干(C++)
假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j ,都有一个尺寸 ...