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. UVA 10859 Placing Lamppost 树形DP+二目标最优解的求解方案

    题意:给定一个无向,无环,无多重边,要求找出最少的若干点,使得,每条边之中至少有一个点上有街灯.在满足上述条件的时候将还需要满足让两个点被选择的边的数量尽量多. 题解: 对于如何求解最小的节点数目这点 ...

  2. Curl之解决中文乱码

    利用iconv命令 curl http://www.baidu.com | iconv -f gb2312 -t utf-8 iconv命令可以将一种已知的字符集文件转换成另一种已知的字符集文件.它的 ...

  3. TCP/IP网络编程之套接字与标准I/O

    标准I/O函数 标准标准I/O函数有两个优点: 标准I/O函数具有良好的移植性 标准I/O函数可以利用缓冲提高性能 关于移植性无需过多解释,不仅是I/O函数,所有标准函数都具有良好的移植性.因为,为了 ...

  4. 回顾Scrum学习:《Scrum实战》第4次课【全职的Scrum Master】作业

    回顾Scrum学习   1.回顾目标 1.1 期望结果 了解和学习Scrum,为将来换方向打好理论基础 如果能在目前公司引入和推行也很好,但是根据目前公司的文化氛围来看,推行希望不大 把敏捷思想应用到 ...

  5. Java多线程-join方法

    thread.Join把指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程.比如在线程B中调用了线程A的Join()方法,直到线程A执行完毕后,才会继续执行线程B. 具体例子看链接 ...

  6. Your branch is ahead of 'origin/master' by 21 commits.

    当切换到主分支后,准备 git pull 拉取远程 master 分支时,提示本地主分支显示有 21 个commits 问题原因: 因为你修改了 local master 本地的主分支,可以选择以下方 ...

  7. git放弃修改&放弃增加文件

    1. 本地修改了一堆文件(并没有使用git add到暂存区),想放弃修改. 单个文件/文件夹: git checkout -- filename 所有文件/文件夹: git checkout . 2. ...

  8. Spring整合hibernate -声明事务管理

     目录 1 sessionFactory 注入HibernateTransactionManager 2 XML配置的配置 3 添加annotation-driven 4 引入JAR包 5在servi ...

  9. xshell 连接redis

    当我们安装好redis 在本地测试启动,存,取都正常,但是无法远程连接redis. 在redis.conf的文件默认配置中有一配置是 bind 127.0.0.1,表示绑定访问该redis的地址只能是 ...

  10. application.properties 详解

    mvc spring.mvc.async.request-timeout设定async请求的超时时间,以毫秒为单位,如果没有设置的话,以具体实现的超时时间为准,比如tomcat的servlet3的话是 ...