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 ...
随机推荐
- PHP MySQLi extension is not loaded
PHP MySQLi extension is not loaded 如何解决呢? yum -y install mysqli.so huozhe yum -y install php-mysql
- Getshell
GetShell 常用免杀大法 一.编码大法 (1).一句话马子本身采用编码 原文:<?php @eval($_GET(a)):?> 转码后:在提交的post的时候可以直接使用\u0026 ...
- 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...
- 01-CentOS 8.1安装 Docker
官方参考地址:https://docs.docker.com/install/linux/docker-ce/centos/ 里面包含包下载地址:https://download.docker.com ...
- 面试官问我CAS,我一点都不慌
文章以纯面试的角度去讲解,所以有很多的细节是未铺垫的. 文章中写到的处理线程安全的思路每一项技术都可以写出一篇文章,AQS.Synchronized.Atomic...周末肝起来!下周再来给大家安排! ...
- 1.2V升3.3V芯片,大电流,应用MCU供电,3.3V稳压源
MCU供电一般是2.5V-5V之间等等都有,1.2V需要升到3.3V的升压芯片来稳压输出3.3V给MCU供电. 同时1.2V的输入电压低,说明供电端的能量也是属于低能量的,对于芯片自身供货是也要求高. ...
- python3多进程 进程池 协程并发
一.进程 我们电脑的应用程序,都是进程,进程是资源分配的单位.进程切换需要的资源最大,效率低. 进程之间相互独立 cpu密集的时候适合用多进程 #多 ...
- https://learnku.com/docs/go-blog/qihoo/6532 。 heap size went up to 69G, with maximum garbage collection (GC)
https://learnku.com/docs/go-blog/qihoo/6532 Use a Task Pool, a mechanism with a group of long-lived ...
- 阿里巴巴微服务与配置中心技术实践之道 配置推送 ConfigurationManagement ConfigDrivenAnyting
阿里巴巴微服务与配置中心技术实践之道 原创: 坤宇 InfoQ 2018-02-08 在面向分布式的微服务系统中,如何通过更高效的配置管理方式,帮助微服务系统架构持续"无痛"的演进 ...
- Python学习【第3篇】:列表魔法
##########################深灰魔法-list类中提供的方法###################list 类,列表list = [1,12,9,"age" ...