A. Far Relative’s Birthday Cake
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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. (1, 2) and (1, 3)
  2. (3, 1) and (3, 3)

Pieces that share the same column are:

  1. (2, 1) and (3, 1)
  2. (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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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这个 ...

  4. Codeforces Round #343 (Div. 2) C. Famil Door and Brackets

    题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #343 (Div. 2)

    居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...

  10. Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP

    题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...

随机推荐

  1. ubuntu 执行Python脚本出现: /usr/bin/env: ‘python\r’: No such file or directory

    原因: #!/usr/bin/env python 在ubuntu会变成 #!/usr/bin/env python\r 而\r 会被shell 当成参数 所以出现:  /usr/bin/env: ‘ ...

  2. Oracle启动与关闭数据库实例

    Oracle数据库启动实例分为3个步骤: 启动实例 加载数据库 打开数据库 通用模式: STARTUP  [ nomount | mount | open | force ]  [resetrict] ...

  3. [Clr via C#读书笔记]Cp7常量和字段

    Cp7常量和字段 常量 常量在编译的时候必须确定,只能一编译器认定的基元类型.被视为静态,不需要static:直接嵌入IL中: 区别ReadOnly 只能在构造的时候初始化,内联初始化. 字段 数据成 ...

  4. 测试模拟 白屏 / FOUC

    白屏和FOUC 白屏与无样式内容闪烁(FOUC)是因为不同浏览器加载与显示页面的机制不同而造成的. 我们可以通过一个实验来进行测试和模拟白屏.FOUC的现象,让我们更好的理解白屏.FOUC. 测试de ...

  5. 正则表达式 和 re 模块

    正则表达式究竟是什么? 在一些网站注册的时候需要输入手机号码,当你输入一个错误的手机号码的时候,会提示你输入的手机号码格式错误 那么他究竟是如何判断的呢? 我们用Python代码进行表示: phone ...

  6. 开源自动驾驶仿真平台 AirSim (1) - Unreal Engine

    AirSim 官方Github: https://github.com/Microsoft/AirSim AirSim 是微软的开源自动驾驶仿真平台(其实它还能做很多事情,这里主要用于自动驾驶仿真研究 ...

  7. [leetcode-658-Find K Closest Elements]

    Given a sorted array, two integers k and x, find the k closest elements to x in the array. The resul ...

  8. Word Ladder Problem (DFS + BFS)

    Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...

  9. Debian 7 amd64 + fbterm + ucimf

    前段时间,显示器出了问题,导致Debian下只有终端显示正常,桌面显示效果很是摇晃模糊.遂起了念头,能不能在终端下就能完成日常的工作. google了很久,终于知道fbterm可以在终端下显示中文,加 ...

  10. js jQuery 判断跳转是手机还是电脑

    <script type="text/javascript"> $(function () { var system = {}; var p = navigator.p ...