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;
    }
  • 相关阅读:
    django-rest-framework
    史上最全的状态码
    __new__、__init__、__call__三个特殊方法
    量化投资与Python之pandas
    MongoDB 3.0 Release Notes
    TokuMX写操作无法加锁的问题
    TokuMX唯一索引不支持dropDups选项
    接着写吧
    Windows下Python IDLE设置
    20145320周岐浩免考
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5205691.html
Copyright © 2011-2022 走看看