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. JVM垃圾回收原理

    原文地址:http://chenchendefeng.iteye.com/blog/455883 一.相关概念 基本回收算法 1. 引用计数(Reference Counting) 比较古老的回收算法 ...

  2. Retrofit 入门和提高

    首先感谢这个哥们,把我从helloworld教会了. http://blog.csdn.net/angcyo/article/details/50351247 retrofit 我花了两天的时间才学会 ...

  3. IOS开发---菜鸟学习之路--(六)-UITableView几个方法的使用说明

    对于UITableView的基础使用我这边就不做重复介绍了 我重点就来介绍下如何实现大部分新闻的界面.也就是第一条记录显示大图片下面加一段文字说明 然后剩下来的内容全部显示为文字图片的格式 其实要做到 ...

  4. Robotium测试报告的生成方法(下)

    7.4 测试报告优化 通过上面的三种方法,我们都可以得到一个Xml格式的测试报告,不过这不是我们想要的,因为这样的报告读起来很费劲,而且这样的报告发给领导们也是不行的.所以我们要美化一下才行,一般都是 ...

  5. Halcon11 Linux 下载

    Halcon11 Linux下载地址:http://www.211xun.com/download_page_3.html HALCON 11 是一套机器视觉图像处理库,由一千多个算子以及底层的数据管 ...

  6. Halcon11 Windows版 下载

    Halcon11 下载地址:http://www.211xun.com/download_page_2.html HALCON 11 是一套机器视觉图像处理库,由一千多个算子以及底层的数据管理核心构成 ...

  7. Leetcode 503.下一个更大元素

    下一个更大元素 给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素.数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大的数,这意味着你 ...

  8. P2165 [AHOI2009]飞行棋

    题目描述 给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列. 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形. 输入输出格式 输入格式: 第一行为 ...

  9. 【CCF】JSON查询

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  10. 贪吃蛇(bzoj 4213)

    Description  最近lwher迷上了贪吃蛇游戏,在玩了几天却从未占满全地图的情况下,他不得不承认自己是一个弱菜,只能改去开发一款更弱的贪吃蛇游戏. 在开发的过程中,lwher脑洞大开,搞了一 ...