Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit
Status

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

Input
4 3
2 1 3 1
Output
5
Input
7 4
4 2 3 1 2 4 3
Output
18

Sample Output

Hint

The answer to the first test sample equals 5 as Sasha can choose:

  1. the first and second books,
  2. the first and third books,
  3. the first and fourth books,
  4. the second and third books,
  5. the third and fourth books.

Source


给了m种书,每种有若干本,让你计算一下挑出两本不一样的方案,
#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(模拟水题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  3. 模拟水题,查看二维数组是否有一列都为1(POJ2864)

    题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...

  4. UVA 10714 Ants 蚂蚁 贪心+模拟 水题

    题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...

  5. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  6. HDU4287-STL模拟水题

    一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...

  7. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  8. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

  9. USACO_1.1_Greedy_Gift_Givers_(模拟+水题)

    描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=gift1 给出不超过$10$个人,每个人拿出一定数量的钱平分给特定的人,求最后每个人 ...

随机推荐

  1. NSLayoutConstraint的使用

    *一切皆代码*- -- #继承关系框架|类|类:-:|:-:|:-:UIKit|NSLayoutConstraint|--|-|- #应用场景UI界面的搭建一般会占用项目开发相当一部分的时间.涉及到控 ...

  2. LUA 创建文件和文件夹

    创建文件: os.execute('mkdir e:\\aa') 创建文件夹: os.execute("cd.>e:\\wang.ini")

  3. P1982 小朋友的数字

    题目描述 有 n 个小朋友排成一列.每个小朋友手上都有一个数字,这个数字可正可负.规定每个 小朋友的特征值等于排在他前面(包括他本人)的小朋友中连续若干个(最少有一个)小朋 友手上的数字之和的最大值. ...

  4. 关于电脑安装新硬盘,出现无法是识别设备,03F0问题解答。

    问题说明:在添加新的硬盘,切确定硬盘没有坏的情况下,无法识别出新的硬盘. 解决方案: 1.检查bios系统里的安全模式,是否处于开启中.因为在windows 8.1以上的版本中,不开启的情况下只能读取 ...

  5. windows server 2008 R2开机进度条闪过后黑屏

    起因:想在2008中添加hyper-v角色 事件经过: 1.在服务器管理器中添加hyper-v角色,重启,一直配置失败. 2.在bios开启vt-x,重新添加hyper-v角色,重启,进度条闪一下之后 ...

  6. JS 输入年份,再输入月份,弹出这个月有多少天?

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. 「BZOJ3339」Rmq Problem(5366)

    题目描述 输入 输出 样例输入 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 提示 这个题说来也挺有意思的 当时集训的时候遇到了一道类似的题,但是题意与此不同,我太菜了, ...

  8. http-server 简介 复制的

    http-server 简介 https://blog.csdn.net/ithanmang/article/details/88375259http-server 是一个简单的零配置的命令行 htt ...

  9. 解析xml文件,遍历输出xml文件中的所有节点, 最终模仿实现struts2框架自动封装参数的功能

    程序结构:src文件夹下存放xml文件 该文件内容: <?xml version="1.0" encoding="UTF-8"?> <myst ...

  10. String 基本使用方法, 以及要注意的事项

    package chengbaoDemo; public class Test01 { public static void main(String[] args) { //字符串的两种创建形式 St ...