Description

 UVa Panel Discussion 

The UVa online judge team is arranging a panel discussion for the next ACM-ICPC World Finals event in Orlando, Florida. They want that three or four of the contestants take part in the panel and as they have about 300 persons for selecting such a little
group, they have decided to put some restrictions in order to reduce the number of possibilities.

After thinking about several options, they finally propose that in case the number of contestants to choice be 3, all of them must be of the same country or from three different countries; and in case the number be 4, at least three of them will be of the
same country or must be from at least three different countries.

Could you help them to calculate the number of different selections they can make following the restrictions above.

Input

The input file contains several test cases; each of them consists of two lines.

The first contains two integers N and
M separated by one space. N (
3N300)
is the number of contestants and M (
1M50)
the total number of different countries. The second line consists of
N integers between 1 and M, separated by a space, representing the country each contestant is from (It is not necessary that contestants will be from
M countries).

Last line of the input will contain two zeroes and it won't be processed.

Output

For each input case write, in a line by itself, two integers separated by a space.

The first integer being be the number of ways to select a group of three people, and the second the number of ways to do it of four people.

Sample Input

3 5
5 4 2
5 3
3 1 3 2 2
10 10
1 8 9 1 6 7 3 4 10 4
0 0

Sample Output

1 0
4 4
104 209

题意:n个队伍,来自m个国家,如今给出3个队伍的可能是:三个都来自一个国家。或者三个都来自不同的国家;4个队伍的可能是:至少有三个来自不同的国家。至少有三个同样的国家

思路:计数问题。首先是3个队伍的情况是比較好计算的。都来自一个国家或者都不一样。都来自一个国家的时候注意去重,4个队伍的情况就分4个都不一样。2个是一样的,3个是一样的。相同要去重

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 100; int n, m, num[maxn]; int main() {
while (scanf("%d%d", &n, &m) != EOF && n+m) {
memset(num, 0, sizeof(num));
int a;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
num[--a]++;
} ll ans3 = 0;
for (int i = 0; i < m; i++) {
if (num[i] >= 3)
ans3 += num[i] * (num[i]-1) * (num[i]-2) / 6;
for (int j = i+1; j < m; j++)
for (int k = j+1; k < m; k++)
ans3 += num[i] * num[j] * num[k];
} ll sum = 0, ans4 = 0;
for (int i = 0; i < m; i++)
sum += num[i];
for (int i = 0; i < m; i++)
if (num[i] >= 3) {
ll tmp = num[i] * (num[i]-1) * (num[i]-2) / 6;
ans4 += tmp * (sum - num[i]);
ans4 += tmp * (num[i] - 3) / 4;
}
for (int i = 0; i < m; i++)
for (int j = i+1; j < m; j++)
for (int k = j+1; k < m; k++) {
ans4 += num[i] * (num[i]-1) / 2 * num[j] * num[k];
ans4 += num[i] * num[j] * (num[j]-1) / 2 * num[k];
ans4 += num[i] * num[j] * num[k] * (num[k]-1) / 2;
}
for (int i = 0; i < m; i++)
for (int j = i+1; j < m; j++)
for (int k = j+1; k < m; k++)
for (int l = k+1; l < m; l++)
ans4 += num[i] * num[j] * num[k] * num[l]; printf("%lld %lld\n", ans3, ans4);
}
return 0;
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVA - 12001 UVa Panel Discussion的更多相关文章

  1. UVa 10318 Security Panel

    题意:给你一个3*3的翻转模版,深色部分表示翻转,浅色部分不变.然后你可以在r*c的矩形里依照模版进行翻转,要求所有点亮所有块.输出最小的步骤. 思路:有一点比较好想.每个块至多被翻转一次,翻两次的效 ...

  2. UVA 10318 Security Panel(DFS剪枝 + 状压 + 思维)题解

    题意:给一个r*c的矩阵开关(初始全打开的),每次按下一个开关都会改变3*3范围内的有*的地方的状态,问你最少几步能让开关全闭上,按升序输出按哪些按钮 思路:每个按钮至多按一下,按按钮的顺序和结果无关 ...

  3. Uva 12124 Uva Live 3971 - Assemble 二分, 判断器, g++不用map.size() 难度:0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  4. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  5. UVA 11624 UVA 10047 两道用 BFS进行最短路搜索的题

    很少用bfs进行最短路搜索,实际BFS有时候挺方便得,省去了建图以及复杂度也降低了O(N*M): UVA 11624 写的比较挫 #include <iostream> #include ...

  6. UVA - 10870 UVA - 10870

    Problem ARecurrencesInput: standard inputOutput: standard output Consider recurrent functions of the ...

  7. Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)

     Count the Trees  Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...

  8. UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题 (例题 7-7)

    传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Probl ...

  9. 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)

    *注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...

随机推荐

  1. oschina Web应用开发

    Web应用开发 SPDY开发包(13) HTML5开发相关(105) Pjax相关项目(4) 网站API(93) REST/RESTful项目(72) 响应式 Web 框架(27) 微信相关软件(63 ...

  2. SUSE Linux 报错:too many open files in system

     现网执行的oracle数据库,有一天突然报错(alert日志):too many open files in system,须要对操作系统同意句柄数进行扩充,查阅了非常多资料,改动点主要集中在例 ...

  3. Gnu Linux下文件的字符编码及转换工具

    /*********************************************************************  * Author  : Samson  * Date   ...

  4. debian下使用siege进行压力测试

    一:siege siege是开源的一个测试工具,可以对指定文本的URL列表进行负载测试,也可以在执行其他请求前让某个请求休眠,从而让你感觉某个用户在转移到web应用的下一个文档前正在读取该文档. ht ...

  5. Wix打包系列(三)自定义Action(Custom Action)

    原文:Wix打包系列(三)自定义Action(Custom Action) 3.1 关于Action 我们已经知道如何生成具有标准安装界面的安装程序了,Windows Installer按照我们的界面 ...

  6. hdu1506(dp求最大子矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 分析: 对于每个单位矩阵,我们先求出连续比它高的最左边的下标假设为l,然后求出比它高的最右边的下 ...

  7. BlueJ的code pad

    Java的REPL BlueJ的code pad实用吗?Java对(Read-Eval-Print Loop)不提供原生支持.这样的"交互式解释器"或"交互式编程环境&q ...

  8. Yii学习笔记之三(在windows 上安装 advanced )

    首先说一下下载地址: http://www.yiiframework.com/download/ 然后将下载下来的文件进行解压到 你指定的文件夹 解压过程中假设报什么错误 直接忽略掉 我的解压文件夹是 ...

  9. [Sqlite] 移动嵌入式数据库Sqlite日报SQL操作语句汇总

    ,EXPLAIN分析 没有建立索引之前.分析都是表扫描: sqlite> EXPLAIN SELECT *  FROM COMPANY  WHERE Salary < 20000; add ...

  10. 最近调试HEVC中码率控制, 发现HM里面一个重大bug

    最近调试HEVC中码率控制, 发现里面一个重大bug! 码率控制中有这么一个函数: Int TEncRCGOP::xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int ...