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 ...
随机推荐
- Ubuntu 16.04修改显示字体大小(包括GNOME/Unity)
在Ubuntu中字体都基本偏大,且和分辨率无关. Unity: 安装Unity Tweak Tool sudo apt-get install unity-tweak-tool GNOME: 打开优化 ...
- Ubuntu和Win7双系统,ubuntu被删,重新启动之后显示,no such partition
准备一张windows7的系统安装盘.从光盘启动电脑,在光盘启动完毕之后.按shift+F10,调出cmd命令终端,在终端输入:bootrec/fixmbr OK.重新启动之后就搞定了
- How to enable Google Play App Signing
how to enable google play app signing ------------------------------------------------------------- ...
- 修改mysql root密码
mysql密码丢失后,在mysql命令行下执行如下命令,即可将root用户密码清空: mysqld_safe --skip-grant-tables& mysql修改密码 mysql修改,可在 ...
- Oracle新建数据库
确定楼主是以管理员身份登录的:1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password ...
- 图像处理之基础---滤波器之高斯低通滤波器3c代码实现yuv,rgb
()高斯理论简介 () ()代码实现 四 使用高斯滤波器进行图像的平滑 ()高斯简介 http://research.microsoft.com/en-us/um/people/kahe/eccv10 ...
- 淘宝数据库OceanBase SQL编译器部分 源代码阅读--生成物理查询计划
SQL编译解析三部曲分为:构建语法树,制定逻辑计划,生成物理运行计划. 前两个步骤请參见我的博客<<淘宝数据库OceanBase SQL编译器部分 源代码阅读--解析SQL语法树>& ...
- 基于百度AI人脸识别技术的Demo
编写demo之前首先浏览官方API:http://ai.baidu.com/docs#/Face-API/top 下面是源码: package com.examsafety.test; import ...
- ffmpeg resize and scale
ffmpeg缩小视频尺寸 | 楚盟博客 https://www.5yun.org/13126.html ffmpeg -i test.mp4 -s 480×360 out.mp4 常用分辨率: 108 ...
- rabbitmq最大连接数(Socket Descriptors)
RabbitMQ自带了显示能够接受的最大连接数,有2种比较直观的方式:1. rabbitmqctl命令. 1 2 3 4 5 6 7 8 9 10 11 12 <span style=" ...