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. poj2245Lotto(最基础的dfs)

    题目链接: 啊哈哈,点我点我 思路:最開始画好搜索状态,然后找好结束条件,最好预推断当前找到的个数和能够找到的是否大于6就可以.. 题目: Lotto Time Limit: 1000MS   Mem ...

  2. [置顶] Android常用适配器控件

    Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...

  3. Effective Objective-C 2.0 笔记三(Literal Syntax简写语法)

         当使用Objective-C的时候,你总会遇到Foundation 框架中的一些类,这些类包含NSString,NSNumber,NSArray和NSDictionary,这些数据结构都是自 ...

  4. SQLServer批量备份与还原

    原文地址:http://www.cnblogs.com/fygh/archive/2011/09/09/2172546.html 备份与还原是数据库避不开的主题,而作为DBA,经常会面临将一台机器上的 ...

  5. cocos2d-x-3.0新建工程以及移植其他平台

    本文来自:http://www.zaojiahua.com/cocos2d-x-3-0.html 有将近俩个礼拜没有研究cocos2dx了,博主最近刷了些ACM的水题,越做感觉越没意思,这哪是考编程啊 ...

  6. 关于git的ssh-key:解决本地多个ssh-key的问题

    在设置github的时候,官方的说明文档要求备份当前的id_rsa.然后生成一份新的私钥用于github的登陆.假设真这样做,那么新的私钥是无法再继续登陆之前的机器的. 这样的方法有点暴力- 还好ss ...

  7. 《Javascript高级程序设计》读书笔记之bind函数详解

    为什么需要bind var name = "The Window"; var object = { name: "My Object", getNameFunc ...

  8. Android ImageButton Example 图片按钮

    Android ImageButton Example 图片按钮 使用“android.widget.ImageButton” 展现一个具有背景图片的按钮 本教程将展现一个具有名字为 c.png背景图 ...

  9. android创建自定义对话框

    创建如下自定义对话框: JAVA代码 LayoutInflater li = LayoutInflater.from(TagActivity. this);  //NOTE final View Te ...

  10. jQuery回到顶部插件jQuery GoUp

    插件描写叙述 jQuery GoUp!是一个简单的jQuery插件,让你的网页用户直接回到顶部. 用法很easy 引用jquery库和jquery.goup.min.js到你的页面 <scrip ...