codeforces 629A Far Relative’s Birthday Cake
1 second
256 megabytes
standard input
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.
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'.
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.
3
.CC
C..
C.C
4
4
CC..
C..C
.CC.
.CC.
9
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, 2) and (1, 3)
- (3, 1) and (3, 3)
Pieces that share the same column are:
- (2, 1) and (3, 1)
- (1, 3) and (3, 3)
题意:一个矩形的蛋糕,C代表巧克力,点(.)代表什么也没有,每一行或者每一列的巧克力的对数代表幸福值,问题目中所给数据的幸福值是多少
题解:记录每一行每一列的C的个数x,然后对其求组合C(x,2)即可,将所有的组合数相加
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 110
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
char s[MAX][MAX];
int row[MAX],col[MAX];
int main()
{
int n,m,j,i,t;
while(scanf("%d",&t)!=EOF)
{
memset(row,0,sizeof(row));//记录每行C的个数
memset(col,0,sizeof(col));//记录每列C的个数
for(i=0;i<t;i++)
scanf("%s",s[i]);
for(i=0;i<t;i++)
{
for(j=0;j<t;j++)
{
if(s[i][j]=='C')
row[i]++;
if(s[j][i]=='C')
{
//printf("%d %d#\n",j,i);
col[i]++;
} }
}
int sum=0;
for(i=0;i<t;i++)
{
//printf("%d\n%d*\n",row[i],col[i]);
sum+=(row[i]*(row[i]-1))/2;//求组合数
sum+=(col[i]*(col[i]-1))/2;
}
printf("%d\n",sum);
}
return 0;
}
codeforces 629A Far Relative’s Birthday Cake的更多相关文章
- 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 ...
- 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 Do ...
- 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 ...
- Codeforces 629 A. Far Relative’s Birthday Cake
A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces--629A--Far Relative’s Birthday Cake(暴力模拟)
Far Relative's Birthday Cake Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d &a ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake
水题 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> ...
- codeforces 629D D. Babaei and Birthday Cake (线段树+dp)
D. Babaei and Birthday Cake time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【20.19%】【codeforces 629D】Babaei and Birthday Cake
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #343 (Div. 2)
居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...
随机推荐
- Android开发之onActivityResult()中的resultCode为0,intent为null的解决办法
BUG:昨天在使用activity之间传值的时候,遇到了一个bug,该bug为:Activity A启动Activity B,然后在Activity B中取到一个值,并通过back键返回到Activi ...
- 安卓自动化测试工具MonkeyRunner之使用ID进行参数化,以及List选择某项和弹出框点击确定的写法
一.List选择某项的操作步骤: 1.通过父结点得出列表各子项 2.将选择项的文本与列表中的子项进行比较 3.计算出选择项的坐标位置 截取实例: from com.android.monkeyrunn ...
- CSS效果
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- 发布 windows 10 universal app 时微软账号验证失败
具体错误:Visual Studio encountered an unexpected network error and can't contact the Microsoft account s ...
- css3的背景多重运用
效果图: 简单代码: http://www.developerdrive.com/2013/08/introducing-css3-multiple-backgrounds/ 演示地址: http:/ ...
- 专题:Windows编译x264、SDL、faac、ffmpeg过程
Windows上编译ffmpeg完整过程,包括编译x264.SDL.faac.在Windows上编译ffmpeg需要用MinGW+msys,本专题用于记录编译过程中遇到的各种问题及解决方法,转载请注明 ...
- 利用ioctl()获取无线速率
其实对于自己装了网卡驱动的来说,应该从最根本的驱动中获取速率. 但是用ioctl()也可以,其实实现和iwconfig命令相同. 仅仅获取速率这部分: #include <stdio.h> ...
- bzoj 1001: [BeiJing2006]狼抓兔子 平面图最小割
平面图跑最大流 可以转换为其对偶图跑最短路 一个环对应一个割 找到最小环(即最短路)极为所求,注意辅助边的建立 加入读入优化 不过时间还是一般 估计是dij写的不好 大神勿喷~~~ /*** ...
- AutoLayout UITableViewCell 动态高度
从这里http://www.cnblogs.com/liandwufan/p/4516956.html?utm_source=tuicool 转载过来的 -(UITableViewCell*)tabl ...
- C# 引用类型的"祸害"
前端时间刚刚弄完一个项目,终于有时间来总结与回顾了. 项目需求:给用户发送邮件,邮件分为系统邮件和个人邮件,需要按时间.未读降序排列. 一开始以为,这是一个很简单的需求,给邮件建了一个对象: clas ...