zoukankan      html  css  js  c++  java
  • Codeforces 629 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)

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<string.h>
     7 #include<set>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<cmath>
    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<n;i++)
    20             scanf("%s",&s[i]);
    21       int h=0;
    22       int ans=0;
    23       while(h<n){
    24           int num=0;
    25           for(int i=0;i<n;i++){
    26               if(s[i][h]=='C')num++;
    27           }
    28           if(num>=2)ans+=num*(num-1)/2;
    29             h++;
    30       }
    31       h=0;
    32       while(h<n){
    33           int num=0;
    34           for(int i=0;i<n;i++){
    35               if(s[h][i]=='C')num++;
    36           }
    37           if(num>=2)ans+=num*(num-1)/2;
    38           h++;
    39       }
    40      printf("%d
    ",ans);
    41    }
    42     return 0;
    43 }
     
  • 相关阅读:
    GitCam一款Gif动画制作软件
    IniParse解析类
    一个网页设计师应该考虑的9件事
    Backit轻松为您的网站创建备份
    [翻译]Web开发牛人访谈:你们都在用什么?
    简单文件服务器
    一个网站访问速度测试工具
    GS运维常用工具及文档
    Oracle快速收集AWR的方案
    Oracle调整内存参后报ORA-00844和ORA-00851
  • 原文地址:https://www.cnblogs.com/ZERO-/p/8052678.html
Copyright © 2011-2022 走看看