CF817B Makes And The Product
思路:
模拟,数学。
实现:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; const int MAXN = ; typedef long long ll; int a[MAXN], last[], num[], n; ll cnm(int n, int m)
{
ll s = ;
int k = ;
if(m > n / )
m = n - m;
for(int i = n - m + ; i <= n; i++)
{
s *= (ll)i;
while(k <= m && s % k == )
{
s /= (ll)k;
k++;
}
}
return s;
} int main()
{
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
int cnt = ;
last[] = ;
int i = ;
while (i < n)
{
if (a[i] != a[last[cnt]])
{
num[cnt] = i - last[cnt];
last[++cnt] = i;
}
if (cnt == ) break;
i++;
}
while (a[i] == a[last[cnt]] && i < n) i++;
num[cnt] = i - last[cnt];
if (num[] >= ) cout << cnm(num[], ) << endl;
else if (num[] == ) cout << num[] << endl;
else if (cnt == || num[] >= ) cout << cnm(num[], ) << endl;
else cout << num[] << endl;
return ;
}
CF817B Makes And The Product的更多相关文章
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [LeetCode] Product of Array Except Self 除本身之外的数组之积
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...
- [LeetCode] Maximum Product Subarray 求最大子数组乘积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- vector - vector product
the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...
- 1 Maximum Product Subarray_Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Leetcode Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Where product development should start
We all need to know our customers in order to create products they’ll actually buy. This is why the ...
- [LintCode] Product of Array Except Self 除本身之外的数组之积
Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WI ...
- sp_addlinkedserver '(null)' is an invalid product name
使用SSMS 2008客户端工具逆向生成了创建链接服务器的脚本时,在测试环境执行是报如下错误:'(null)' is an invalid product name. USE [master] GO ...
随机推荐
- c++11中的线程、锁和条件变量
void func(int i, double d, const string& s) { cout << i << ", " << d ...
- Python学习系列之文件操作
Pyhton文件打开方式 with= open('文件路径','打开模式') as f:#PS:python3提供了with语句来帮我们自动调用close方法,所以说无论打开文件是否出错都能自动正确的 ...
- HDU2577 How to Type【DP】
题目链接: pid=2577">http://acm.hdu.edu.cn/showproblem.php? pid=2577 题目大意: 给你一个仅仅包括大写和小写字母的字符串,如今 ...
- jquery 联动 年月日
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JQuery实例 - 生成年 ...
- Woody的逻辑游戏--怎样换轮胎
题目:有一个做长途运输的司机要出发了,他用作运输的车是三轮车.轮胎的寿命是2万里,如今他要进行5万里的长途运输.计划用8个轮胎完毕运输任务,如何才干做到呢? 首先将轮胎从1-8依次编号,然后例如以下所 ...
- struts <s:iterator>两个list嵌套循环,对象属性交叉使用
两个list:List<CreateTableColumn> createTableColumnList,List<Map<String, Object>> tab ...
- 【hdu3966】Aragorn's Story
题意:给一棵树,并给定各个点权的值,然后有3种操作:I C1 C2 K: 把C1与C2的路径上的所有点权值加上KD C1 C2 K:把C1与C2的路径上的所有点权值减去KQ C:查询节点编号为C的权值 ...
- Estimating duration from bitrate, this may be inaccurate
通过 ffmpeg 获取 媒体 播放时长 ./ffmpeg-linux64-v3.3.1 -i /tmp/mp30001.mp3 ffmpeg version N-86111-ga441aa90e8 ...
- 利用JFreeChart生成折线图 (4) (转自 JSP开发技术大全)
利用JFreeChart生成折线图 (4) (转自 JSP开发技术大全) 14.4 利用JFreeChart生成折线图 通过JFreeChart插件,既可以生成普通效果的折线图,也可以生成3D效果的折 ...
- 2-5 原生小程序 - 语法缺点.mp4