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. http_load安装与测试参数分析 - 追求自由自在的编程 - ITeye技术网站

    http_load安装与测试参数分析 - 追求自由自在的编程 - ITeye技术网站 http_load -p 50 -s 120 urls

  2. Semaphore实现Andoird版源代码剖析

    Semaphore是一个计数的信号量.从概念上来说,信号量维持一组许可(permits).acquire方法在必须的时候都会堵塞直到有一个许可可用,然后就会拿走这个许可.release方法加入一个许可 ...

  3. HDU 3277 Marriage Match III(二分+最大流)

    HDU 3277 Marriage Match III 题目链接 题意:n个女孩n个男孩,每一个女孩能够和一些男孩配对,此外还能够和k个随意的男孩配对.然后有些女孩是朋友,满足这个朋友圈里面的人.假设 ...

  4. PostgreSQL服务端监听设置及client连接方法

    背景介绍: PostgreSQL服务端执行在RedHat Linux上,IP为:192.168.230.128 client安装在Windows XP上, IP为:192.168.230.1 配置方法 ...

  5. 50 tips of JavaScript

    50 tips of JavaScript,这些坑你都知道吗? 1.在局部作用域中,使用var操作符定义的变量将成为定义该变量的作用域中的局部变量,省略var的会创建全局变量:在全局作用域中,不管是否 ...

  6. 云计算分布式大数据神器Spark实战高手之旅

    从2012年1月份研究Spark到如今已经两年多的时间了. 在这两年多的时间里比較彻底的研究了Spark的源码并已经在2014年4月24日编写完毕了世界上第一本Spark书籍. 鉴于CSDN在大陆IT ...

  7. maven项目建立pom.xml报无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3

    一.发现问题 建立maven项目后,pom.xml在显示红叉.鼠标放上去,显示Executiondefault-testResources of goalorg.apache.maven.plugin ...

  8. HDU-2647拓扑排序

    这道题不能用矩阵表示,因为1w*1w绝对超内存,分析数据,前一个a的钱要多于后一个b,所以我们要把b作为出度,a为入度,如果不明白这个地方,举例:b——>a——>c——>d ,b为8 ...

  9. 它们的定义AlertDialog(二)

    先来看主页面布局 main_activity.xml里面仅仅有一个button(加入点击事件.弹出载入框) 再看MainActivity package com.example.loadingdial ...

  10. Applet 数字签名技术完全攻略

      这里说声对不起大家.毕竟2几年前,我想写这篇文章,但因为他才懒得一直没有写.同时也给自己的东西好.前些日子我老大让我又搞这个东西发现我曾经的资料没留,又凭着自己印象从新来过.但发现网上写的东西真的 ...