A. Far Relative’s Birthday Cake
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)

题意:一个矩形的蛋糕,C代表巧克力,点(.)代表什么也没有,每一行或者每一列的巧克力的对数代表幸福值,问题目中所给数据的幸福值是多少

题解:记录每一行每一列的C的个数x,然后对其求组合C(x,2)即可,将所有的组合数相加

#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 110
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
char s[MAX][MAX];
int row[MAX],col[MAX];
int main()
{
int n,m,j,i,t;
while(scanf("%d",&t)!=EOF)
{
memset(row,0,sizeof(row));//记录每行C的个数
memset(col,0,sizeof(col));//记录每列C的个数
for(i=0;i<t;i++)
scanf("%s",s[i]);
for(i=0;i<t;i++)
{
for(j=0;j<t;j++)
{
if(s[i][j]=='C')
row[i]++;
if(s[j][i]=='C')
{
//printf("%d %d#\n",j,i);
col[i]++;
} }
}
int sum=0;
for(i=0;i<t;i++)
{
//printf("%d\n%d*\n",row[i],col[i]);
sum+=(row[i]*(row[i]-1))/2;//求组合数
sum+=(col[i]*(col[i]-1))/2;
}
printf("%d\n",sum);
}
return 0;
}

  

codeforces 629A 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 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

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

  4. Codeforces 629 A. Far Relative’s Birthday Cake

      A. Far Relative’s Birthday Cake   time limit per test 1 second memory limit per test 256 megabytes ...

  5. Codeforces--629A--Far Relative’s Birthday Cake(暴力模拟)

    Far Relative's Birthday Cake Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d &a ...

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

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

  7. codeforces 629D D. Babaei and Birthday Cake (线段树+dp)

    D. Babaei and Birthday Cake time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. 【20.19%】【codeforces 629D】Babaei and Birthday Cake

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. Codeforces Round #343 (Div. 2)

    居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...

随机推荐

  1. sh.exe": grunt: command not found

    今天在git命令行工具中使用 grunt的时候,总是提示我找不到grunt命令,如: sh.exe": grunt: command not found 但是我运行 npm install ...

  2. Asp.Net时间戳与时间互转

    /// <summary> /// 时间戳转成时间类型 /// </summary> /// <param name="timeStamp">& ...

  3. listagg 函数

    listagg 函数--oracle 11g release 2 转载:http://xpchild.blog.163.com/blog/static/10180985920108485721969/ ...

  4. android错误 Android NAND: nand_dev_load_disk_state,

    Android NAND: nand_dev_load_disk_state, 总是提示上面这个错误,我以为是内存分配不足呢,但是内存足够用也不行,后来在国外的网站上看到这个问题的解答,说是把用到的A ...

  5. 证明:寝室分配问题是NPC问题

    P.NP.NPC.NP-hard P:多项式时间能够解决的问题的集合,比如最短路径问题是集合P的一个元素,而最短路径问题本身又是一个集合,因此P是集合的集合. NP:多项式时间内能够验证的问题的集合. ...

  6. angular js 实例参数学习

    <!DOCTYPE html> <html> <head> <meta name="description" content=" ...

  7. hdu 3496 Watch The Movie

    题意:题目给定N部电影,每部电影有时长和价值,要求看M部电影,并且时间控制在L以内,转化为背包问题,让我们在N件物品中找正好M件物品塞进容量L的包中,求最大的价值.// dp[i][j] 表示在容量为 ...

  8. 去除 waring Method 'CreateNew' hides virtual method of base type 'TCustomForm'

    最近整理前人的代码,有好多的hint和waring, 其中整理到Method 'CreateNew' hides virtual method of base type 'TCustomForm', ...

  9. mybatis+spring+struts2框架整合

     近期公司要开发新的项目,要用struts2+mybatis+spring框架,所以学习了下,来自己的博客发表下,希望能给大家带来帮助!下边我把我的myschool开发的源代码以及数据库贴出来!  开 ...

  10. Asp.net TextBox常规输入验证

    Asp.net TextBox只能输入数字<asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execComma ...