Codeforces Round #343 (Div. 2) A
1 second
256 megabytes
standard input
standard output
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.
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'.
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.
3
.CC
C..
C.C
4
4
CC..
C..C
.CC.
.CC.
9
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)
开学了 额
题意: n*n矩阵 每行每列 C两两配对 共有多少种
题解: 遍历一遍 记录每行每列C的个数 求组合数 相加
#include<iostream>
#include<cstring>
#include<map>
#include<cstdio>
using namespace std;
int n;
char a[105][105];
map<int,int>m;
map<int,int>p;
int main()
{
scanf("%d",&n);
getchar();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]=='C')
{
m[i]=m[i]+1;
p[j]=p[j]+1;
}
}
getchar();
}
int sum=0;
for(int i=1;i<=n;i++)
{
sum=sum+m[i]*(m[i]-1)/2+p[i]*(p[i]-1)/2;
}
printf("%d\n",sum);
Codeforces Round #343 (Div. 2) A的更多相关文章
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets dp
C. Famil Door and Brackets 题目连接: http://www.codeforces.com/contest/629/problem/C Description As Fami ...
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads
题目链接: http://www.codeforces.com/contest/629/problem/E 题解: 树形dp. siz[x]为x这颗子树的节点个数(包括x自己) dep[x]表示x这个 ...
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为 ...
- Codeforces Round #343 (Div. 2) B
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads lca 树形dp
E. Famil Door and Roads 题目连接: http://www.codeforces.com/contest/629/problem/E Description Famil Door ...
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp
D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题
A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...
- Codeforces Round #343 (Div. 2)
居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...
- Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP
题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...
随机推荐
- 213. String Compression【LintCode java】
Description Implement a method to perform basic string compression using the counts of repeated char ...
- POJ 1269 Intersecting Lines(直线求交点)
Description We all know that a pair of distinct points on a plane defines a line and that a pair of ...
- ide的tomcat的部署和配置
关于intellij ide的tomcat的部署和配置 1.下载zip版的Tomcat 7,并解压.下载地址 2.在IDEA中配置Tomcat 7 在idea中的Settings(Ctrl+Alt ...
- c++SDK c#调用_疑难杂症
在编写过程中,会不时遇到各种问题: 1.dll明显在和exe同一目录下但调用不成功, 2.运行正常,没有报错,参数数值运行过程中也一致,但结果就是达不到预想, 都是dll没有引用完全造成的影响. 推荐 ...
- c#调用c++dll(c++界面在c#显示)____制作dll
1.c++dll含界面,以摄像头dll为例: 1.直接在c++SDK上调试运行成功,生成dll. 2.留一个调用接口(格式如下,写在cpp文件中,即函数体): extern "C" ...
- encode 与 decode
decode 将其它编码的字符串转换成unicode编码,例如:str1.decode("gb2312"),表示将gb2312编码的字符串转换成unicode编码 encode 将 ...
- 【IdentityServer4文档】- 欢迎来到 IdentityServer4
欢迎来到 IdentityServer4 IdentityServer4 是一款包含和实现了 OpenID Connect 和 OAuth 2.0 协议的,适用于 ASP.NET Core 的框架 . ...
- MySQL加密算法
1.不可逆加密: PASSWORD(),ENCRYPT(,),MD5(),SHA5(). 2.可逆的加密算法: ENCODE(,) DECODE(,):加密解密字符串.该函数有两个参数:被加密或解 ...
- Git命令基本操作
本文从以下九个方面,介绍Git命令的基本操作: 一. Git安装 二. Git基本配置 三. 创建Git仓库 四. 获得Git仓库 五. 提交更新 六. 提交历史查看 七. 远程仓库 八. 打Tags ...
- 【Linux】- CentOS查看IP
1.查询命令: ip addr 显示如图: 可以看到ens33没有inet这个属性,那么就没办法通过IP远程连接. 2.设置配置文件: vi /etc/sysconfig/network-script ...