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


相关推荐

  • mysql 字符串转数字再排序

    mysql 字符串转数字再排序如果数字是按照字符串格式存储的排序时候又想按照数字排血 只需要在orderby后加上转换函数即可例如: orderby CONVERT(sort,DECIMAL)可用的类型    二进制,同带binary前缀的效果:BINARY   字符型,可带参数:CHAR()    日期:DATE    时间:TIME    日期时间

    2022年5月7日
    247
  • 数据结构与算法学习笔记

    本文是王争老师的《算法与数据结构之美》的学习笔记,详细内容请看王争的专栏。有不懂的地方指出来,我做修改。数据结构与算法思维导图数据结构指的是“一组数据的存储结构”,算法指的是“操作数据的一组方法”。数据结构是为算法服务的,算法是要作用再特定的数据结构上的。最常用的数据结构预算法:数据结构:数组、链表、栈、队列、散列表、二叉树‘、堆、跳表、图、Tire树 算法:递归…

    2022年4月7日
    210
  • 三分钟彻底理解冒泡排序

    三分钟彻底理解冒泡排序0.如果遇到相等的值不进行交换,那这种排序方式是稳定的排序方式。1.原理:比较两个相邻的元素,将值大的元素交换到右边2.思路:依次比较相邻的两个数,将比较小的数放在前面,比较大的数放在后面。(1

    2022年7月2日
    26
  • 从零开始学习UCOSII操作系统4–任务管理

    从零开始学习UCOSII操作系统4–任务管理从零开始学习UCOSII操作系统4–任务管理1、重讲任务(1)任务可以是一个无限的循环,也可以在一次执行完毕后被删除。这里需要注意的是,任务的代码并不是真正的删除了,而是UCOSII不再理会该任务代码,所以该任务代码不会再执行。(2)建立任务,OSTaskCreate()如果想让UCOSII管理用户的任务,必须先建立任务,可以通过将任务的地址(函数名)和其他参数传递到

    2022年5月24日
    42
  • 通过全备+主从同步恢复被drop的库或表

    通过全备+主从同步恢复被drop的库或表

    2021年6月9日
    83
  • 免费申请国外免费域名超详细教程「建议收藏」

    免费申请国外免费域名超详细教程「建议收藏」1.首先申请免费域名网站:https://my.freenom.com/domains.php2.填入域名,这里我们以xcflag为列(尽量选择复杂一点的或者五个字母以上的域名,因为简单的有些域名是需要收费的),点击检查可用性。3.可以看到很多免费的域名(用的谷歌翻译插件,翻译有时候不是很准确,free翻译过来应该是免费而不是自由,之后会写一些关于谷歌插件的笔记,详细讲解)4.我们选择xcflag.tk点击立即获取,稍等一会点击购物车查看绿色按钮5.默认三个月试用,这里下拉框我们选择十二个月

    2022年6月30日
    152

发表回复

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

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