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

    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;
    }
  • 相关阅读:
    2020系统综合实践 第五次实践作业
    2020系统综合实践 第4次实践作业
    2020系统综合实践 第3次实践作业
    2020系统综合实践 第2次实践作业
    2020系统综合实践 第1次实践作业
    wireshark大作业——负载均衡
    第07组 Beta版本演示
    第07组 Beta冲刺(4/4)
    软工实践个人总结
    第03组 Beta冲刺(5/5)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5205691.html
Copyright © 2011-2022 走看看