A. Far Relative’s Birthday Cake

题目连接:

http://www.codeforces.com/contest/629/problem/A

Description

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.

Sample Input

4

CC..

C..C

.CC.

.CC.

Sample Output

9

Hint

题意

给你一个n*n的矩阵,然后矩阵分钟的C会和在他同一行、同一列的C发生关系

然后问你一共发生多少次关系(嘿嘿嘿

题解:

水题啦

统计每一行有多少个,每一列有多少个,然后n*(n-1)/2就好了

代码

#include<bits/stdc++.h>
using namespace std; char s[120][120]; int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%s",s[i]);
int tot = 0;
long long ans = 0;
for(int i=0;i<n;i++)
{
int tot = 0;
for(int j=0;j<n;j++)
if(s[i][j]=='C')
tot++;
ans += tot*(tot-1)/2;
tot = 0;
for(int j=0;j<n;j++)
if(s[j][i]=='C')
tot++;
ans+=tot*(tot-1)/2;
}
cout<<ans<<endl;
}

最新文章

  1. [Python学习] Linux环境下的Python配置,必备库的安装配置
  2. jQuery+ASP.NET MVC基于CORS实现带cookie的跨域ajax请求
  3. [No000024]鲜为人知的编程真相
  4. Bots(逆元,递推)
  5. mvc-4控制器和状态(1)
  6. [转载]为什么我希望用C而不是C++来实现ZeroMQ
  7. JS 之如何在插入元素时插在原有元素的前面而不是末尾
  8. JavaScript笔记(二)——常用数组、字符串方法的应用
  9. 利用cocoapods管理开源项目,支持 pod install安装整个流程记录(github公有库)
  10. Linux下tomcat运行时jvm内存分配
  11. Lucky 7 (容斥原理 + 中国剩余定理)
  12. 官方解析Cookies和Session的区别
  13. lombok @Builder注解使用的例子、反编译之后的代码详解
  14. Incircle and Circumcircle(二分+几何)浙大月赛zoj3806(详解版)图
  15. C#编程(五十六)----------可观察的集合ObservableCollection
  16. C# ref和out的本质
  17. LUA中点号和冒号的区别
  18. 又见Python&lt;1&gt;:使用Anaconda搭建Python开发环境(Windows7)
  19. 在dropDownList中实现既能输入一个新值又能实现下拉选的代码
  20. while循环 for循环的理解

热门文章

  1. Java 关于微信公众号支付总结附代码
  2. gcc中的内嵌汇编语言(Intel i386平台)
  3. Linux汇编教程04:寻址方式
  4. 安全测试===sqlmap(零)转载
  5. python爬虫模块之调度模块
  6. HDU 6186 CS Course 前缀和,后缀和
  7. 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集
  8. Canvas 高级
  9. Linux下通过jstat命令查看jvm的GC情况
  10. 关于aspxgridview里面过长内容只显示的一部分的处理方案