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 ...
随机推荐
- 【EXP】根据字段导出数据query
exp有些时候需要根据字段来进行导出操作 例如:想要导出hr用户中的employees中salary要大于4000的数据 这样的话需要添加where语句,需要用到的参数是query 查看下大于4000 ...
- ABAP program lines are wider than the internal table
错误详细描述: An exception occurred that is explained in detail below.The exception, which is assigned to ...
- Table controls and tabstrip controls
本文转载自http://www.cnblogs.com/clsoho/archive/2010/01/21/1653268.html ONTROLS Syntax Forms Declaration ...
- 微信小程序代码上传,审核发布小程序
1.打开微信开发者工具 管理员扫码 -> 填写好小程序的项目目录.AppID(必须是客户已注册好的AppID).项目名称 2.在app.js中修改id(客户登录后台管理系统的id),app.js ...
- 单台服务器-利用docker搭建Redis哨兵集群模式
前言:只有一台华为云服务器,所以打算创建三个容器来模拟三个服务器了. 一:拉取redis镜像 二:拉取redis.conf文件 放在自定义的目录下:wget -c http://download.re ...
- vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". Expected String with value "0", got Number with value 0.
vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". ...
- Markdown 编辑器+同步预览+文件笔记管理+静态博客 metadata 管理
Leanote: 1. 笔记管理, 支持富文本, markdown, 写作模式.... 编辑器绝对好用. 另外特意为coder制作了一个贴代码的插件, 真是太贴心(因为作者也是coder) 2. 博客 ...
- testng学习笔记-- beforeclass和afterclass
一.定义 类之前和类之后运行的方法 使用场景: 类运行之前是否需要静态方法,变量赋值,写完其他方法都可以用了 二.标签代码 三.运行结果
- 解决键冲突 — Redis 设计与实现 https://redisbook.com/preview/dict/collision_resolution.html
解决键冲突 - Redis 设计与实现 https://redisbook.com/preview/dict/collision_resolution.html
- HTTPS学习(二):原理与实践
div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...