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’表示巧克力,’.’表示空,如果任一行或者任一列有两个巧克力,小明的快乐度会加一,问小明的快乐度是多少 。

【分析】:实际就是,问同一列两个一组的组合数和同一行两个一组和组合数的和。

【代码】:

#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<streambuf>
#include<cmath>
#include<string>
using namespace std;
#define ll long long
#define oo 10000000
char a[][];
int cnt;
int sum;
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%s",&a[i]);
sum=;
for(int i=;i<n;i++)
{
cnt=;
for(int j=;j<n;j++)
{
if(a[i][j]=='C')
{
cnt++;
}
}
sum+=(cnt)*(cnt-)/;
} for(int j=;j<n;j++)
{
cnt=;
for(int i=;i<n;i++)
{
if(a[i][j]=='C')
{
cnt++;
}
}
sum+=(cnt)*(cnt-)/;
}
printf("%d\n",sum);
return ;
}

暴力

Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake【暴力/组合数】的更多相关文章

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

  2. Codeforces Round #343 (Div. 2)-629A. Far Relative’s Birthday Cake 629B. Far Relative’s Problem

    A. Far Relative's Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake

    水题 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> ...

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

  5. Codeforces Round #343 (Div. 2) B. Far Relative’s Problem

    题意:n个人,在规定时间范围内,找到最多有多少对男女能一起出面. 思路:ans=max(2*min(一天中有多少个人能出面)) #include<iostream> #include< ...

  6. Codeforces Round #343 (Div. 2)

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

  7. Codeforces Round #343 (Div. 2) A

    A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Codeforces Round #343 (Div. 2)【A,B水题】

    A. Far Relative's Birthday Cake 题意: 求在同一行.同一列的巧克力对数. 分析: 水题~样例搞明白再下笔! 代码: #include<iostream> u ...

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

随机推荐

  1. Kali 安装VMtools(最新)

    老方法安装的VMtools不能进行主宿切换,下面是kali最新版安装VMtools的方法 一.换国内源&更新源 参考 Kali 2017更新源 二.安装VMtools apt-get inst ...

  2. RDLC Reporting in Visual Studio 2017

    原文:RDLC Reporting in Visual Studio 2017 Visual Studio 2017 中可以使用 RDLC Reporting 插件来设计报表,SAP Crystal ...

  3. 某面试公司出的面试题---用JS比较两个版本号高低

    一天中午某个公司给我反馈的面试题,说,比较两个文件的版本号,然后我给发过去了,说我的代码不符合他的要求,o(╯□╰)o了var compareVersion = compareVersion||fun ...

  4. cf984e Elevator

    ref我好菜啊 #include <iostream> #include <cstring> #include <cstdio> #include <cmat ...

  5. Asp.net自定义控件开发任我行(5)-嵌入资源上

    摘要 上一篇我们讲了VitwState保存控件状态,此章我们来讲讲嵌入css文件,js文件,嵌入Image文件我也一笔带过. 内容 随着我的控件的完善,我们目标控件DropDwonCheckList最 ...

  6. CSU-2173 Use FFT

    CSU-2173 Use FFT Description Bobo computes the product P(x)⋅Q(x)=\(c_0 + c_1x + - + c_{n+m}x^{n + m} ...

  7. Leetcode 655.输出二叉树

    输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 行数 m 应当等于给定二叉树的高度. 列数 n 应当总是奇数. 根节点的值(以字符串格式给出)应当放在可放置的第一行正中间. ...

  8. Log4j官方文档翻译(六、日志的级别)

    org.apache.log4j.Level 类提供了下面几种日志级别,你也可以通过继承这些类,自定义级别 ALL 所有日志级别都包括 DEBUG 指定信息事件的粒度是DEBUG,在调试应用的时候会有 ...

  9. BZOJ-1043 [HAOI2008]下落的圆盘

    几何题... 先把所有圆储存起来,然后对于每个圆我们求得之后放下的圆挡住了的部分,求个并集,并把没被挡到的周长加进答案. #include <cstdlib> #include <c ...

  10. [ZJOI2014][bzoj3527]力 [FFT]

    题面 传送门 思路 把要求的公式列出来: $E_i=\frac{F_i}{q_i}=\sum_{j=1}^i\frac{q_j}{\left(i-j\right)^2}-\sum_{j=i+1}^n\ ...