CodeForcess--609B--The Best Gift(模拟水题)
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are
n books on sale from one of
m genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from
1 to m.
Input
The first line contains two positive integers n and
m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence a1, a2, ..., an, where
ai (1 ≤ ai ≤ m) equals the genre of the
i-th book.
It is guaranteed that for each genre there is at least one book of that genre.
Output
Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value
2·109.
Sample Input
4 3
2 1 3 1
5
7 4
4 2 3 1 2 4 3
18
Sample Output
Hint
The answer to the first test sample equals 5 as Sasha can choose:
- the first and second books,
- the first and third books,
- the first and fourth books,
- the second and third books,
- the third and fourth books.
Source
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[20],m,n;
long long ans;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
int a;
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
scanf("%d",&a);
vis[a]++;
}
for(int i=1;i<=10;i++)
{
ans+=vis[i]*(n-vis[i]);
}
printf("%lld\n",ans/2);
}
return 0;
}
CodeForcess--609B--The Best Gift(模拟水题)的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- HDU4287-STL模拟水题
一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- USACO_1.1_Greedy_Gift_Givers_(模拟+水题)
描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=gift1 给出不超过$10$个人,每个人拿出一定数量的钱平分给特定的人,求最后每个人 ...
随机推荐
- 超级简单的利用javascript实现文件拖拽事件
1.效果图: 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %& ...
- javascript 将单词首字母大写,其余小写
// 1 别人写的,我拿来参考了一下 function titleCase(str) { var array = str.toLowerCase().split(" "); for ...
- 04-手把手教你把Vim改装成一个IDE编程环境(图文)
Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用的IDE是何等的重 ...
- Spring依赖注入:@Autowired,@Resource和@Inject区别与实现原理
一.spring依赖注入使用方式 @Autowired是spring框架提供的实现依赖注入的注解,主要支持在set方法,field,构造函数中完成bean注入,注入方式为通过类型查找bean,即byT ...
- SaltStact自动化运维工具01
什么是saltstackSaltstack是基于python开发的一套C/S架构配置管理工具使用SSL证书签方的方式进行认证管理底层使用ZeroMQ消息队列pub/sub方式通信 – 号称世界 ...
- 如何在php中优雅的地调用python程序
1.准备工作 安装有python和php环境的电脑一台. 2.书写程序. php程序如下 我们也可以将exec('python test.py') 换成 system('python test.p ...
- Centos 7.2 安装和卸载 MySQL 5.7
一.背景 闲暇之余在虚拟机安装了 Centos 7.2 系统,按照 <简单安装MySQL(RPM方式)> 这篇文章安装 MySQL ,发现由于包依赖的问题安装失败,于是索性在官网查询相关文 ...
- Python笔记22-----高阶函数
1.sorted(排序对象,key=):排序对象可以是类别,也可以是字符串和字典,key为自定义排序,如:[key=abs,按绝对值排序][key=lambda x:x[1],按排序对象的第二个值排序 ...
- JS防抖与节流
在进行窗口的resize.scroll,输入框内容校验等操作时,如果事件处理函数调用的频率无限制,会加重浏览器的负担,导致用户体验非常糟糕.此时我们可以采用debounce(防抖)和throttle( ...
- react实现简单倒计时
今天遇到一个简单的小功能,看网上的一些方法感觉不太适合,所以就手敲了一个,直接上代码!!! import React, { Component } from 'react'; class NoTime ...