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)

代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
const int N=+;
char s[N][N];
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%s",&s[i]);
  int h=;
  int ans=;
   while(h<n){
   int num=;
   for(int i=;i<n;i++){
   if(s[i][h]=='C')num++;
  }
   if(num>=)ans+=num*(num-)/;
     h++;
   }
   h=;
   while(h<n){
   int num=;
   for(int i=;i<n;i++){
   if(s[h][i]=='C')num++;
   }
   if(num>=)ans+=num*(num-)/;
   h++;
   }
   printf("%d\n",ans);
 }
return ;
}
 

Codeforces Round #343 (Div. 2)-629A. Far Relative’s Birthday Cake 629B. Far Relative’s Problem的更多相关文章

  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) A. Far Relative’s Birthday Cake【暴力/组合数】

    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 import java.util.*; import java.io.*; public class Main { ...

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

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

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

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

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

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

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

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

  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. [array] leetcode - 34. Search for a Range - Medium

    leetcode - 34. Search for a Range - Medium descrition Given an array of integers sorted in ascending ...

  2. MySQL锁总结

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/78 MySQL 锁基础 参考了何登成老师文章的结构MySQL 加 ...

  3. [置顶] 几行代码实现ofo首页小黄人眼睛加速感应转动

    最新版的ofo 小黄车的首页小黄人眼睛随重力而转动,感觉有点炫酷,学习一下吧,以下代码是在xamarin android下实现 ofo首页效果图: xamarin android实现效果: 实现思路: ...

  4. Nodejs真.多线程处理

    前言 Threads à gogo 是nodejs 的原生模块,使用这个模块可以让nodejs 具备多线程处理功能 安装方法 npm install threads_a_gogo 下载测试源码 git ...

  5. java 类的继承和接口的继承

    父类 public class person { String name; int age; void eat(){ System.out.println("吃饭"); } voi ...

  6. js 停止事件冒泡 阻止浏览器的默认行为(阻止a标签跳转 )

    在前端开发工作中,由于浏览器兼容性等问题,我们会经常用到"停止事件冒泡"和"阻止浏览器默认行为". 1..停止事件冒泡 JavaScript代码 //如果提供了 ...

  7. Logback分别打印info日志和error日志

    <?xml version="1.0" encoding="utf-8" ?><configuration> <appender ...

  8. oracle里的优化器

    1.1 oracle里的优化器 RBO(Rule-Based-Optinizer):基于规则的优化器 CBO(Cost-Based-Optinizer): 基于成本的优化器 SQL语句执行过程 待执行 ...

  9. [转]Android sharedpreferences使用

    1.    SharedPerferences保存的数据主要是类似配置信息格式的数据,因此它保存的数据主要是简单类型的key-value对,SharedPreferences本身并没有写入数据的能力, ...

  10. Gulp-静态网页模块化

    前言: 在做纯静态页面开发的过程中,难免会遇到一些的尴尬问题.比如:整套代码有50个页面,其中有40个页面顶部和底部模块相同.那么同样的两段代码我们复制了40遍(最难受的方法).然后,这个问题就这样解 ...