codeforce817B Makes And The Product (排序)
来源:互联网 发布:js 数组 按50为一批 编辑:程序博客网 时间:2024/04/30 08:07
题目链接:http://codeforces.com/problemset/problem/817/B
题目大意:让你找出三个最小的数,并且求解这三个数有几种组合的情况
解题思路:先新建数组存数字,然后再排序,再新建一个数组,用来存储每个数出现的次数(不知道算不算离散化),最后进行讨论处理。
代码:
#include <bits/stdc++.h>using namespace std;#define ll long longconst int maxn=1e5+20;ll b[maxn];ll a[maxn];int main(){ int x;scanf("%d",&x); memset(a,0,sizeof(a)); for(int i=0;i<x;i++) scanf("%lld",&b[i]); sort(b,b+x); int flag=0;ll tmp=b[0]; int sum=1; for(int i=1;i<x;i++){ if(tmp!=b[i]){ a[flag++]=sum; tmp=b[i]; sum=1; } else sum++; } a[flag]=sum; //cout<<a[0]<<endl; int n=3; ll ans[4]; memset(ans,0,sizeof(ans)); int i=0; for(int j=1;j<=3;j++){ if(n!=0) while(!a[i]) i++; if(a[i]>=n){ if(n!=0) ans[j]=a[i]; else ans[j]=0; n=0; } else{ ans[j]=a[i]; n-=a[i]; } i++; } if(ans[2]==0){ printf("%lld\n",ans[1]*(ans[1]-1)*(ans[1]-2)/6); } else{ if(ans[3]==0){ if(ans[1]==1) printf("%lld\n",1*(ans[2]*(ans[2]-1))/2); else printf("%lld\n",1*ans[2]); } else printf("%lld\n",ans[1]*ans[2]*ans[3]); }}
阅读全文
1 0
- codeforce817B Makes And The Product (排序)
- codeforces817b Makes And The Product
- Codeforces 817B Makes And The Product
- 【Codeforces 817B. Makes And The Product】
- Educational Codeforces Round 23 B. Makes And The Product
- Educational Codeforces Round 23#B. Makes And The Product
- CodeForces-817B Makes And The Product 解题报告
- CodeFroces 817B. Makes And The Product(构造)
- Six Sigma and the Product Development Cycle
- HDU1027Ignatius and the Princess II(排序)
- haircut makes the good mood
- 131.View the Exhibit and examine the structure of the PRODUCT, COMPONENT, and PDT_COMP tables.
- Platform Road Map for the MATLAB and Simulink Product Families
- 解决安装photoshop提示”please uninstall and reinstall the product“
- 解决安装photoshop提示”please uninstall and reinstall the product“
- OLAP vs OLTP: what makes the difference
- Coding the Matrix: Week 6 Gaussian Elimination and the Inner Product 学习笔记
- Hadamard and Kronecker product
- IC设计基础系列之低功耗篇7:(数字IC)低功耗设计入门(七)——门级电路低功耗设计优化(续)
- n皇后问题(回溯)
- mysql下载地址
- 398. Random Pick Index
- 如何利用minikube 快速安装 kubernetes
- codeforce817B Makes And The Product (排序)
- 淘淘商城系列——删除购物车商品及购物车总结
- Ubuntu16.04安装TensorFlow教程
- 文章标题
- MATLAB 基本命令
- 【框架整合】一、spring+springMVC框架搭建
- PyCharm使用技巧:Inspect Code(代码静态审查)
- 电力拖动自动控制系统(序)
- android命名规范