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 { ...
随机推荐
- 1930. Ivan's Car(spfa)
1930 简单二维 标记一下是上坡还是下坡 #include <iostream> #include<cstdio> #include<cstring> #incl ...
- sdut 1728 编辑距离问题( dp )
题目 思路:edit(i, j),它表示第一个字符串的长度为i的子串到第二个字符串的长度为j的子串的编辑距离. 有如下动态规划公式: if i == 0 且 j == 0,edit(i, j) = 0 ...
- 函数ut_bit_set_nth
/*****************************************************************//** Sets the nth bit of a ulint. ...
- 4010: [HNOI2015]菜肴制作
拓扑排序+堆. 转自popoqqq神犇. 反向建图跑拓扑排序然后逆序输出. 为什么不能正的来呢,因为不知道选当前菜要先制作哪种菜. 逆序过来跑拓扑的话,也能保证满足限制条件编号小的在前面. 题外话:我 ...
- java分层架构概念
转自:http://www.cnblogs.com/bdqnbenet/p/4924778.html service是业务层 DAO (Data Access Object) 数据访问 1.JAVA中 ...
- 基于ffmpeg的流媒体服务器
OS:ubuntu 12.04ffmpeg:N-47141-g4063bb2x264:0.133.2334 a3ac64b目标:使用ffserver建立流媒体服务器使用ffmpeg对本地文件流化(x2 ...
- eclipse集承jboss服务器
eclipse Kepler + Jboss7.1 参考引用文档: http://www.tekdigest.com/how-to-install-jboss-tools-in-eclipse.htm ...
- 怎么制作生成苹果手机app应用的下载二维码图片
原文网址:http://jingyan.baidu.com/article/8065f87ff654262331249886.html app store应用生成二维码操作步骤: 1.首先在MAC上的 ...
- 给table中某一列的文字右对齐
一般来说,没写过jquery的前端人员,肯定是定义一个class,给每一行的那列加上align_r{text-align:right}.这是很麻烦的. 所以用jquery来写,可以$("ta ...
- 数据来自后台非Ajax加载的联动实现方法
要实现的效果如下,通过一级标签来控制二级标签, 第一步:在Conctroller中获取数据,并且请到modle里面返回 ModelAndView model = new ModelAndView(&q ...