UVA – 12001 UVa Panel Discussion

UVA – 12001 UVa Panel Discussion

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

Description

Download as PDF



  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 ( 3$ \le$N$ \le$300) is the number of contestants and M ( 1$ \le$M$ \le$50) 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;
}


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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117569.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • ILRuntime学习[通俗易懂]

    ILRuntime学习[通俗易懂]ILRuntime介绍ILRuntime项目为基于C#的平台(例如Unity)提供了一个纯C#实现,快速、方便且可靠的IL运行时,使得能够在不支持JIT的硬件环境(如iOS)能够实现代码的热更新ILRuntime优势访问C#工程的现成代码,无需额外抽象脚本API直接使用VS2015进行开发,ILRuntime的解译引擎支持.Net4.6编译的DLL执行效率是L#的10-20倍选…

    2022年10月25日
  • Linux 安装 Nginx 并搭建 Tomcat 集群

    Linux 安装 Nginx 并搭建 Tomcat 集群

    2021年8月31日
  • onmouseover 和onmousemove的区别「建议收藏」

    onmouseover 和onmousemove的区别「建议收藏」时间上 onmousemove事件触发后,再触发onmouseover事件。按钮上 不区分鼠标按钮。动作上 onmouseover只在刚进入区域时触发。onmousemove除了刚进入区域触发外,在区域内移动鼠标,也会触发该事件。当鼠标移动很快时,可能不会触发这两个事件。 onmouseover与onmousemove的区别是:当鼠标移过当…

    2022年8月30日
  • windows10安装cuda anaconda_电脑自带cuda吗

    windows10安装cuda anaconda_电脑自带cuda吗cuda10.2安装前言下载cuda10.2和cudnn查看本机驱动版本安装过程安装cudnn验证前言tensorflow1.12之后gpu使用cuda10.0对应的驱动,不要求安装cuda,[但pytorch要求安装cuda和cudnn(暂不确定)],如果本机的驱动版本小于cuda10.0对应的驱动版本,建议安装cuda10.x的驱动来覆盖本机的驱动,不用卸载再安装驱动下载cuda10.2…

    2022年9月23日
  • python3基础:操作mysql数据库

    python3基础:操作mysql数据库mysql登陆基本操作:登陆:mysql-uroot-h127.0.0.1-P3306-pmysql-uroot-p(本机不用写host)退出mysql:ctrl+z+回车,或者exit端口号默认是3306,但是可以通过安装目录下的配置文件修改。使用流程引用API模块获取与数据库的连接执行sql语句与存储过程关闭数据库连接安装pymysqlpython3与…

    2022年6月1日
  • Android UI Design

    Android UI Design

    2021年9月6日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号