2020NYIST个人积分赛第八场-H

题面

原题链接:CodeForces - 629A

Door’s family is going celebrate Famil Doors’s birthday party. They love Famil Door so they are planning to make his birthday cake weird!

The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door’s happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors’s family is wondering what is the amount of happiness of Famil going to be?

Please, note that any pair can be counted no more than once, as two different cells can’t share both the same row and the same column.

Input
In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake.

Then follow n lines, each containing n characters. Empty cells are denoted with ‘.’, while cells that contain chocolates are denoted by ‘C’.

Output
Print the value of Famil Door’s happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.

Examples
Input
3
.CC
C…
C.C
Output
4
Input
4
CC…
C…C
.CC.
.CC.
Output
9
Note
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:

(1, 2) and (1, 3)
(3, 1) and (3, 3)
Pieces that share the same column are:
(2, 1) and (3, 1)
(1, 3) and (3, 3)

题意

给你一个矩形蛋糕,C代表巧克力,“.”表示空。每一行每一列的巧克力的对数 代表幸福值,问题目中所给数据的幸福值是多少

思路

记录每一行每一列的巧克力(C)的个数x,然后求组合数 c(x,2)的值,并将所有组合数相加。

代码

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <vector>
using namespace std;
char s[202][202];
int h[202020], l[202020];
int main()
{
	int n;
	cin >> n;
	memset(h, 0, sizeof(h));
	memset(l, 0, sizeof(l));
	for (int i = 0; i < n;i++)
		cin >> s[i];
	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < n;j++)
		{
			if(s[i][j]=='C')
				h[i]++;//记录每一行的个数
			if(s[j][i]=='C')
				l[i]++;//记录第j列每行的个数
		}
	}
	int sum = 0;
	for (int i = 0; i < n;i++)//求组合数
	{
		sum += (h[i] * (h[i] - 1)) / 2;
		sum += (l[i] * (l[i] - 1)) / 2;
	}
	cout << sum << endl;
}
CCF大数据与计算智能大-面向电信行业存量用户的智能套餐个性化匹配模型联通-复第二名-【多分类,embedding】.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值