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;
    }
  • 相关阅读:
    商用 三色灯 显示屏 原理概述
    高速LVDS时序到底怎么看
    quartus qsys sdram IP 使用
    Avalon 总线 时序 介绍
    以太网 mac层传输 verilog 测试程序
    quartus15.1 下程程序 电脑蓝屏 解决方法
    vivado 波形保存以及arp
    quartus timequest 使用过程中的笔记
    Modelsim 仿真指令force用法
    开发笔记(一)Kintex
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5205691.html
Copyright © 2011-2022 走看看