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!!!!