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


相关推荐

  • a算法解决八数码实验报告_人工智能核心算法

    a算法解决八数码实验报告_人工智能核心算法实验一A*算法求解8数码问题一、实验目的熟悉和掌握启发式搜索的定义、估价函数和算法过程,并利用A*算法求解N数码难题,理解求解流程和搜索顺序。二、实验原理A*算法是一种启发式图搜索算法,其特点在于对估价函数的定义上。对于一般的启发式图搜索,总是选择估价函数f值最小的节点作为扩展节点。因此,f是根据需要找到一条最小代价路径的观点来估算节点的,所以,可考虑每个节点n的估价函数值为两个分量:从起始节点到节点n的实际代价g(n)以及从节点n到达目标节点的估价代价h(n),且hn≤h*n,h*n

    2022年10月30日
    0
  • Mac 安装Yarn「建议收藏」

    Mac 安装Yarn「建议收藏」前言近期学习ant-design-vue-pro,需要使用Yarn安装相关依赖包,以下说说在Mac上安装Yarn的尝试几种安装方式使用homebrew安装brewinstallyarn等待许久后,得到如下错误,尝试无数次后放弃,建议在良好的网络环境下尝试脚本安装curl-o–Lhttps://yarnpkg.com/install.sh|bash安装截图:简单快速,强烈建议尝试,尤其适用在国内网络环境下适用。总结homebrew适宜在网络环境良好的情况下使

    2022年5月26日
    34
  • 微信小程序—图片色彩分析(拾取图片的配色方案)「建议收藏」

    微信小程序—图片色彩分析(拾取图片的配色方案)「建议收藏」这是一款图分析图片配色方案demo,图片色彩分析或许可以应用在智能分析色彩领域,比如穿衣搭配、家装等设计或生活领域,但需要大量数据的支持,希望技术能够更好的被应用

    2022年6月29日
    70
  • Map和Set的区别_list与set的区别

    Map和Set的区别_list与set的区别目录一、简述二、Map三、Set四、Set和Map区别一、简述Set和Map主要的应用场景在于数据重组和数据储存。Set是一种叫做集合的数据结构,Map是一种叫做字典的数据结构。集合(Set):ES6新增的一种新的数据结构,类似于数组,成员唯一(内部元素没有重复的值)。且使用键对数据排序即顺序存储。Set本身是一种构造函数,用来生成Set数据结构。Set对象允许你储存任何类型的唯一值,无论是原始值或者是对象引用。二、Ma…

    2022年9月6日
    2
  • 了解图形数据库_图形数据库neo4j

    了解图形数据库_图形数据库neo4j企业架构师应该知道什么您在Google上获得的图表数据库的描述主要是学术性的。我看到很多关于图形数据库的描述,它们讨论了Königsberg的七座桥梁或互联网的发明者Berners-Lee。有理论和愿景很好,但对我来说,我仍然认为引导相关性很重要。为什么图形数据库对您很重要?想象一下存储在当地连锁餐厅的数据。如果您要跟踪,则将客户信息存储在一个数据库表中,将您提供的项目存储在另一个数据…

    2022年10月29日
    0
  • Java学习之Mybatis框架基础篇

    0x00前言续上篇文章的入门篇,继续markMybatis内容,上一章节只是写了Mybatis的一个简单查询功能,这篇来写他的删改查等其他操作。0x01Mybatis增加大法添加的操作和查

    2021年12月12日
    41

发表回复

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

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