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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • oracle索引视图_位图联合索引

    oracle索引视图_位图联合索引一.什么是位图索引我们目前大量使用的索引一般主要是B*Tree索引,在索引结构中存储着键值和键值的RowID,并且是一一对应的.而位图索引主要针对大量相同值的列而创建(例如:类别,操作员,部门ID,库房ID等),索引块的一个索引行中存储键值和起止Rowid,以及这些键值的位置编码,位置编码中的每一位表示键值对应的数据行的有无.一个位图索引块可能指向的是几十甚至成百上千行数据的位置.这种方式存储数据…

    2025年7月17日
    3
  • 个人服务器搭建违法_自建服务器

    个人服务器搭建违法_自建服务器在win10系统上,安装git,作为客户端安装:Git-2.18.0-64-bit.exe安装步骤:都是简单的安装过程,只截图简单表示下只有第4、8两步有点更改1选择安装路径。234我选择了用notepad++作为编辑器5678修改默认的控制台,用windows的cmd.exe9最后一步创建了10完成转载于:https://…

    2022年9月28日
    2
  • 万能乘法速算法大全_小学数学各年级知识点和重点、难点大全,复习必备提纲!…

    万能乘法速算法大全_小学数学各年级知识点和重点、难点大全,复习必备提纲!…今天小数老师为不同年级的学生整理出小学数学重要知识点帮助小伙伴们及时查缺补漏哦!一年级的知识重点1数与计算(1)20以内数的认识,加法和减法。数数。数的组成、顺序、大小、读法和写法。加法和减法。连加、连减和加减混合式题(2)100以内数的认识。加法和减法。数数。个位、十位。数的顺序、大小、读法和写法。两位数加、减整十数和两位数加、减一位数的口算。两步计算的加减式题。2量与计量钟面的认识(…

    2022年6月7日
    63
  • Activity工作流引擎学习笔记(一)「建议收藏」

    Activity工作流引擎学习笔记(一)「建议收藏」工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程自动进行,从而实现某个预期的业务目标,或者促使此目标的实现”。工作流管理系统(WorkflowManagementSystem,WfMS)是一个软件系统,它完成工作量的定义和管理,并按照在系统中预先定义

    2022年7月11日
    20
  • 发现制作CSS导航菜单工具CSS Tab Designer

    发现制作CSS导航菜单工具CSS Tab Designer

    2021年7月24日
    53

发表回复

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

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