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. java二维码生成代码

    QRCodeUtil.encode(text, "D:/004.jpg", "D:", true, "exp");// 这个方法的第一个参数 ...

  2. [置顶] webapi token、参数签名是如何生成的

    一个问题 在这里我想问大家一句,如果你向一个刚刚接触.net web后端程序开发的同学(别人刚刚也就学了webform的request,response,会提交表单的这种刚接触不久的同学),你怎么去解 ...

  3. Xamarin Android Gestures详解

    通过Gesture的监听我们将实现一个,手指的快速滑动显示坐标的变化,我们先来看一看效果图: 1.Android中手势交互的执行顺序 1.手指触碰屏幕时,触发MotionEvent事件! 2.该事件被 ...

  4. 两个HC-05蓝牙模块互相绑定构成无线串口模块

    HC-05 嵌入式蓝牙串口通讯模块(以下简称模块)具有两种工作模式:命令响应工作模式和自动连接工作模式,在自动连接工作模式下模块又可分为主(Master).从(Slave)和回环(Loopback)三 ...

  5. bzoj 1179: [Apio2009]Atm

    Description Input 第 一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路 的起点和终点的 ...

  6. ArcGIS API for Javascript 加载天地图(经纬度投影)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. SecureCRT连接本地的Vmware虚拟机(CentOS)时提示连接超时“Connection timed out”

    测试了一下,直接在Vmware的VM里面可以ping通宿主机. 但是宿主机无法ping通VM. 后面发现是本地的网络设置里面的vmware的NAT的网卡设置了手工填写地址和DNS. 修改为自动获取.问 ...

  8. Oracle学习笔记_07_模糊查询

    附录:参考资料 1.Oracle sql语言模糊查询--like后面的通配符 2.oracle sql语言模糊查询--通配符like的使用教程

  9. c# 去除字符串中重复字符

    String.Join 和 Distinct 方法 https://www.cnblogs.com/louby/p/6224960.html 1.在写程序中经常操作字符串,需要去重,以前我的用方式利用 ...

  10. HTML5图片上传本地预览

    在开发 H5 应用的时候碰到一个问题,应用只需要一张小的缩略图,而用户用手机上传的确是一张大图,手机摄像机拍的图片好几 M,这可要浪费很多流量. 我们可以通过以下方式来解决. 获取图片 通过 File ...