CodeForces - 817B Makes And The Product(水题+思维) 解题报告 Apare_xzc

21 篇文章 1 订阅
7 篇文章 0 订阅

CodeForces - 817B Makes And The Product(水题+思维) 解题报告

xzc 2019/3/30

vjudge链接

codeforces链接


题意:
给一个长度为n(3<=n<=1E5)数列,这个数列中取出三个数,乘积最小,这样的取法有多少种?


Sample:

Input
4
1 1 1 1
Output
4

Input
5
1 3 2 3 4
Output
2

Input
6
1 3 3 1 3 2
Output
1

思路:

  • 肯定先从小到大排序,得到前三个为x,y,z
  • 我们设数列中所有值为z的元素为b
  • 若y!=z,那么答案就是b
  • 若y=z但x!=y, 那么答案就是C(2,b)
  • 若x=y=z, 那么答案就是C(3,b)
  • 注意算组合数的时候要用long long, 不然可能会乘爆

代码:

#include <bits/stdc++.h>
#define Mst(a,b) memset(a,(b),sizeof(a))
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long 
using namespace std;
const int maxn = 1e5 + 100;
int a[maxn]; 
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
  	int n;
  	while(cin>>n)
	{
	  	For(i,0,n-1) scanf("%d",a+i);
	  	sort(a,a+n);
	  	int ans = 0;
	  	For(i,3,n-1)
	  	{
	  		if(a[i]==a[2]) ++ans;
	  		else break;
		}
		if(a[1]<a[2])
		{
			cout<<ans+1<<endl;
			continue;
		}
		if(a[1]==a[2]&&a[0]<a[1])
		{
			ans += 2;
			LL res = 1ll*ans*(ans-1)/2;
			cout<<res<<endl; 
		} 
		if(a[1]==a[0]&&a[1]==a[2])
		{
			ans += 3;
			LL res = 1ll*ans*(ans-1)*(ans-2)/6;
			cout<<res<<endl; 
		}
		
	} 
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值