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. 土司论坛nc反弹神器使用方法

    说明: PS:我本机是linux,因为没有服务器所以使用win7来演示.倘若你是windows可以在本机生成dll以后再放到服务器上面去执行dll即可反弹shell物理机ip:192.168.1.12 ...

  2. Linux 内核同步之自旋锁与信号量的异同【转】

    转自:http://blog.csdn.net/liuxd3000/article/details/8567070 Linux 设备驱动中必须解决的一个问题是多个进程对共享资源的并发访问,并发访问会导 ...

  3. C++学习之路(一):const与define,结构体对齐,new/delete

    前言:针对C++ Primer和Effective C++两本书,以及技术博客与实验测试,本系列主要是针对C++进行系统化学习,记录学习中遇到的问题和经验. (一)const与define 关于con ...

  4. device tree property ---- interrupt-names

    device tree source 的 interrupt-names property 會對應到 pltform_get_irq_byname() 的第二個參數. .dtsi or .dts in ...

  5. centos 安装flash

    linux系统中安装flash插件 linux中安装flashplayer插件的简单方法: 1.下载其中最新版本的播放器,下载地址: http://get.adobe.com/cn/flashplay ...

  6. python近期遇到的一些面试问题(一)

    整理一下最近被问到的一些高频率的面试问题.总结一下方便日后复习巩固用,同时希望可以帮助一些朋友们. 1.python的基本数据类型 主要核心类型分为两类不可变类型:数字(int float bool ...

  7. Kettle提高输入输出数据总结

    1 mysql在数据连接是可以通过设置一下三个三处的方式 useServerPrepStmts=false       useCursorFetch=true      useCompression= ...

  8. [hadoop][会装]zookeeper安装

    1.简介 分布式场景下的各个进程间的协调运作离不开zookeeper, zookeeper已经是大数据领域提供分布式协调服务的事实标准. 本文只介绍zookeeper的安装方法. 2. 节点规划如下: ...

  9. tomcat8特性

    作者:Eilen,转载需注明.博客主页:http://www.cnblogs.com/Eilen/ 一.Apache Tomcat 8介绍 Apache Tomcat 8RC1版于前几日发布.它 经过 ...

  10. HTML5晃动DeviceMotionEvent事件

      关于devicemotion html5提供了几个新的DOM事件来获得设备物理方向及运动的信息,包括:陀螺仪.罗盘及加速计. 第一个DOM事件是**deviceorientation**,其提供设 ...