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. 提领NULL指针

    通常之中导致程序崩溃的最重要的原因是试图取消引用NULL指针.正如在以前的文章中指出,智能指针RefCountPtr和ScopedPtr它提供了一个诊断的执行时间. 但,并不是所有的指针是所有的对象都 ...

  2. Kafka 协议实现中的内存优化

    Kafka 协议实现中的内存优化 Kafka 协议实现中的内存优化   Jusfr 原创,转载请注明来自博客园 Request 与 Response 的响应格式 Request 与 Response ...

  3. -bash: ./job.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录

    昨天在windows下用写字板写了个shell脚本,使用winscp上传到linux上运行的时候发现运行不了,提示-bash: ./job.sh: /bin/sh^M: bad interpreter ...

  4. I2C操作笔记——以 AT24C04为例

    1.前言     对于大多数project师而言,I2C永远是一个头疼的问题.相比UART和SPI而言,I2C的时序要复杂一些,I2C组合变化也丰富一些.在这里以AT24C04为例说明I2C使用过程中 ...

  5. &quot;ScrollView can host only one direct child&quot;问题解决了

    1. 问题叙述性说明: (请注意以下几点大胆). ScrollView作为顶层view时报错,直接导致apk崩溃.具体错误信息例如以下: 12-21 09:12:15.150: D/AndroidRu ...

  6. Redis key 设计技巧

    1: 把表名转换为key前缀 如, tag: 2: 第2段放置用于区分区key的字段--对应mysql中的主键的列名,如userid 3: 第3段放置主键值,如2,3,4...., a , b ,c ...

  7. 使用Nexus搭建企业maven仓库(二)

    先阅读<使用Nexus搭建企业maven仓库(一)> http://blog.csdn.net/ouyida3/article/details/40747545 1.官网眼下最新的版本号是 ...

  8. ThinkPHP中的volist标签中使用eq标签出错

    参考地址:http://blog.csdn.net/luquansen/article/details/18310855 源码: <volist id="v" name=&q ...

  9. SWT的CheckBoxTreeView

    其实CheckBoxTreeView和TreeView基本上是一样的,他们共同的方法有: TreeViewer 类封装了tree控件.树查看器按照父子关系来显示分等级的对象列表.此查看器需要设置标签供 ...

  10. 一个极其简洁的Python网页抓取程序,自己主动从雅虎財经抓取股票数据

    本程序使用Python 2.7.6编写,扩展了Python自带的HTMLParser,自己主动依据预设的股票代码列表,从Yahoo Finance抓取列表中的数据日期.股票名称.实时报价.当日变化率. ...