CF1475-C. Ball in Berland
CF1475-C. Ball in Berland
题意:
一个班级有\(a\)个男生和\(b\)个女生,现在这个班级有\(k\)对男女愿意一起出席毕业典礼,这里注意\(k\)对男女中可能会有某个男生或女生出现在多个\(pair\)中。
你从这\(k\)对中找出两对,使得这两对中的男生不相同、女生不相同,即一个男生或女生不可能在一个典礼中出现在两对中。
让你求出一共有多少种可能的组合方式。
思路:
枚举这\(k\)对,假设每对描述为\((b_i, g_i)\),那么\(k\)减去与\(b_i,g_i\)配对的人的数量\(N_{(b_i,g_i)}\),就是确定了\((b_i,g_i)\)之后可能的情况数。
那么答案\(ans=\frac{\sum_{i=1}^kN_{b_i,g_i}}2\),之所以要除以2是因为每个情况都会被计算两遍,比如对于枚举\((b_i,g_i)\)的时候会枚举到\((b_j,g_j)\),那么枚举到\((b_j,g_j)\)的时候同样也会枚举到\((b_i,g_i)\)。
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long ll;
const int Maxn = 200005;
int in[Maxn][2];
/*
* in[i][0]:第i组的男生的编号
* in[i][1]:第i组的女生的编号
*/
int degree[2][Maxn];
/*
* degree[0][i]:与第i个男生配对的数量
* degree[1][i]:与第i个女生配对的数量
*/
void solve() {
memset(degree, 0, sizeof degree);
int a, b, k;
scanf("%d %d %d", &a, &b, &k);
for (int i = 0; i < k; i++) {
scanf("%d", &in[i][0]);
degree[0][in[i][0]]++;
}
for (int i = 0; i < k; i++) {
scanf("%d", &in[i][1]);
degree[1][in[i][1]]++;
}
ll ans = 0;
for (int i = 0; i < k; i++) {
int u = in[i][0];
int v = in[i][1];
ans += k - degree[0][u] - degree[1][v] + 1;
// +1 是因为当前枚举的pair被减掉两次
}
printf("%lld\n", ans / 2);
}
int main() {
// freopen("/Users/chant/in.txt", "r", stdin);
int T;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
CF1475-C. Ball in Berland的更多相关文章
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- Codeforces Round #697 (Div. 3)
A.Odd Divisor 题意:问一个数是不是含有奇数因子 思路:就直接给这个数循环除以2,看看最后剩下的数是不是0,如果不是就有奇数因子,如果是就没有 想不到:1)当时想着用log2来解决问题,后 ...
- CF 370B Berland Bingo
题目链接: 传送门 Berland Bingo time limit per test:1 second memory limit per test:256 megabytes Descrip ...
- CodeForces 489B BerSU Ball (贪心)
BerSU Ball 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/E Description The Berland Stat ...
- B. Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players p ...
- Codeforces Round #277.5 (Div. 2)B——BerSU Ball
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Yet Another Ball Problem
Yet Another Ball Problem time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #277.5 (Div. 2) B. BerSU Ball【贪心/双指针/每两个跳舞的人可以配对,并且他们两个的绝对值只差小于等于1,求最多匹配多少对】
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 怎么判断innodb 日志缓冲区该设置为多大呢
怎么判断innodb 日志缓冲区该设置为多大呢
- ASP.NET Core错误处理中间件[2]: 开发者异常页面
<呈现错误信息>通过几个简单的实例演示了如何呈现一个错误页面,该过程由3个对应的中间件来完成.下面先介绍用来呈现开发者异常页面的DeveloperExceptionPageMiddlewa ...
- CTF------pwn笔记
地址:http://pwnable.kr/play.php 题目: 使用MobaXterm连接(当然也可以使用别的软件进行连接,用的顺手就行) 连接成功后所以"ls"命令查看目录 ...
- 记一次ceph pg unfound处理过程
今天检查ceph集群,发现有pg丢失,于是就有了本文~~~ 1.查看集群状态 [root@k8snode001 ~]# ceph health detail HEALTH_ERR 1/973013 o ...
- Kubernetes调整Node节点快速驱逐pod的时间
在高可用的k8s集群中,当Node节点挂掉,kubelet无法提供工作的时候,pod将会自动调度到其他的节点上去,而调度到节点上的时间需要我们慎重考量,因为它决定了生产的稳定性.可靠性,更快的迁移可以 ...
- mybatis源码分析之走进缓存
之前写了一篇关于mybatis缓存的读后感,想了想还是把缓存模块简单分析一下,附赠下载地址:https://github.com/MyBatis/MyBatis-3,github直接搜排名很靠前的. ...
- 多路复用器Select、Poll、Epoll区别梳理
注意:本文是本人的学习总结,可能存在理解上的错误,请带着怀疑眼光看待,如果有不准确的地方欢迎指出,疑义相与析.为了叙述完整性,前面有一些前置知识,可以根据目录直接看后面的详解部分. 前置知识 用户态与 ...
- Dubbo 最基本的几个需求
需求 http://dubbo.apache.org/zh-cn/docs/user/preface/requirements.html 在大规模服务化之前,应用可能只是通过 RMI 或 Hessia ...
- 微博CacheService架构浅析 对底层协议进行适配
https://mp.weixin.qq.com/s/wPR0j2bmHBF6z0ZjTlz_4A 麦俊生 InfoQ 2014-04-21 微博作为国内最大的社交媒体网站之一,每天承载着亿万用户的服 ...
- (007)每日SQL学习:将字符和数字分离
with aa as ( select 'sad10' as data from dual union all select 'datf20' as data from dual union all ...