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


相关推荐

  • CentOS安装EPEL软件源

    CentOS安装EPEL软件源CentOS安装EPEL软件源

    2022年4月24日
    57
  • 尺度空间家具_空间尺度分析

    尺度空间家具_空间尺度分析尺度空间的基本思想:在视觉信息(图像信息)处理模型中引入一个被视为尺度的参数,通过连续变化尺度参数获得不同尺度下视觉处理信息,然后综合这些信息以深入地挖掘图像的本质特征。尺度空间方法将传统的单尺度视觉信息处理技术纳入尺度不断变化的动态构架中,因此更容易获得图像的本质特征。尺度空间生成的目的是模拟图像数据的多尺度特征。尺度空间理论是通过对原始图像进行尺度变换,获得图像多尺度下的尺度空间表示

    2022年8月31日
    3
  • C# -XML用法(XmlDocument )

    C# -XML用法(XmlDocument )使用visualstudio中自带的xml解析器,引入System.Xml命名空间。1.向文件中写入配置xml文件实现效果:&amp;lt;?xmlversion=&quot;1.0&quot;encoding=&quot;utf-8&quot;?&amp;gt;&amp;lt;某某某某公司&amp;gt;&amp;lt;执行董事兼总经理&amp;gt;曾振帅&amp;lt;/执行董事兼总经

    2022年6月19日
    64
  • java 死链检测_网站死链检测工具/网站地图生成工具「建议收藏」

    java 死链检测_网站死链检测工具/网站地图生成工具「建议收藏」转载自http://www.yshjava.cn/post/483.html今天在谷歌站长工具上看到谷歌爬虫在笔者的个人博客网站上找到了3个无效的404链接,稍微有一点SEO常识的人都知道,404是搜索引擎爬虫非常讨厌的页面,会直接降低网站在搜索引擎中的权重和排名,这是广大站长都不愿意看到的事情。如果自己手动的去寻找这些404页面,或许很难:404存在于哪些页面中?出现一次还是多次?偶然还是必然…

    2022年7月23日
    18
  • SCrollTOP scrollHeight

    SCrollTOP scrollHeightjQuery里和滚动条有关的概念很多,但是有三个属性和滚动条的拖动有关,就是:scrollTop、scrollLeft、scrollHeight。其中scrollHeight属性,互联网上几乎搜素不到关于它的应用技巧,而我正好需要用到它。   我们现在只探讨和垂直滚动有关的scrollTop、scrollHeight属性。   一、滚动条有关属性的正确理解: 

    2022年7月24日
    11
  • clion永久激活码 Ubuntu_通用破解码

    clion永久激活码 Ubuntu_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    303

发表回复

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

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