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;
}

Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题的更多相关文章

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

  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

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

  4. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

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

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

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

  7. Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  8. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  9. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

随机推荐

  1. Eclipse svn 忽略文件夹/ svn 设置不同步

    Eclipse 开发中我们经常用到SVN插件, 但是对于某些文件的缓存来说, 我们只要有操作缓存便会保存一次, 每次提交很是麻烦, 小编这里教你一种不同步某个文件夹的方法 工具/原料 MyEclips ...

  2. 配置连接的IP、端口、以及相应的数据库

    解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. //使用autoload加载相关库,这边重点就是为了requir ...

  3. Linux 入门记录:七、fdisk 分区工具

    一.fdisk分区工具 fdisk 是来自 IBM 的老牌分区工具,支持绝大多数操作系统,几乎所有的 Linux 发行版都装有 fdisk,包括在 Linux 的 resuce 模式下依然能够使用. ...

  4. python实战===一句python代码搭建FTP服务

    环境搭建: python windows/linux pip install pyftpdlib  (安装失败请到这里下载:https://pypi.python.org/pypi/pyftpdlib ...

  5. jdk1.8在linux环境下的安装

    转自博客:http://www.cnblogs.com/ShawnYuki/p/6816179.html

  6. eetcode 之String to Integer (atoi)(28)

    字符串转为数字,细节题.要考虑空格.正负号,当转化的数字超过最大或最小是怎么办. int atoi(char *str) { int len = strlen(str); ; ; ; while (s ...

  7. LeetCode解题报告—— Rotate List & Set Matrix Zeroes & Sort Colors

    1. Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. Exam ...

  8. hdu 1247 (字典树入门)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. 怎么WordPress增加在线投稿功能

    现在很多个人博客为了增加博客的内容,都会提供投稿通道,大部分都是以邮箱的形式进行投稿,不过这样一来,也很费人力,要拷贝复制,然后编辑等.如果给博客加个在线投稿功能,那就方便多了.稍微审核下文章内容就可 ...

  10. 限制输入字符个数的jq插件

    (function($) { $.fn.extend( { limiter: function(limit, elem) { $(this).on("keyup focus", f ...