博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 629 A. Far Relative’s Birthday Cake
阅读量:5123 次
发布时间:2019-06-13

本文共 2238 字,大约阅读时间需要 7 分钟。

 
 
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)

 

代码:

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std;14 const int N=100+10;15 char s[N][N];16 int main(){17 int n;18 while(~scanf("%d",&n)){19 for(int i=0;i
=2)ans+=num*(num-1)/2;29      h++;30    }31    h=0;32    while(h
=2)ans+=num*(num-1)/2;38    h++;39    }40    printf("%d\n",ans);41  }42 return 0;43 }

 

 

 

 

 

转载于:https://www.cnblogs.com/ZERO-/p/8052678.html

你可能感兴趣的文章
js阻止事件冒泡的两种方法
查看>>
Java异常抛出
查看>>
CGRect知多少
查看>>
Android 开发环境安装配置手册
查看>>
[SQL Server 系] T-SQL数据库的创建与修改
查看>>
74HC164应用
查看>>
变量声明和定义的关系
查看>>
Wpf 之Canvas介绍
查看>>
linux history
查看>>
除去内容中的空格与换行
查看>>
jQuery on(),live(),trigger()
查看>>
Python2.7 urlparse
查看>>
sencha touch在华为emotion ui 2.0自带浏览器中圆角溢出的bug
查看>>
【架构】Linux的架构(architecture)
查看>>
ASM 图解
查看>>
Date Picker控件:
查看>>
svn在linux下的使用(svn命令行)ubuntu 删除 新增 添加 提交 状态查询 恢复
查看>>
java处理url中的特殊字符%等
查看>>
你的第一个Django程序
查看>>
Tomcat免安装版的环境变量配置以及Eclipse下的Tomcat配置和测试
查看>>