Codeforces Round #343 (Div. 2) -A. Far Relative’s Birthday Cake(组合+模拟)
来源:互联网 发布:知敬畏守规矩讲话稿 编辑:程序博客网 时间:2024/05/29 15:20
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 length1. 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.CCC..C.C
4
4CC..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)
- (2, 1) and (3, 1)
- (1, 3) and (3, 3)
#include<iostream>#include<functional>#include<algorithm>#include<cstring>#include<string>#include<vector>#include<cstdio>#include<queue>#include<cmath>#include<map>#include<set>using namespace std;#define CRL(a) memset(a,0,sizeof(a))#define QWQ ios::sync_with_stdio(0)#define inf 0x3f3f3f3ftypedef unsigned long long LL;typedef long long ll;const int T = 500+50;const int mod = 1000000007;char s[T][T];int col[T],row[T];ll fun(int x){ll sum = x;if(x>3)return sum*(sum-1)/2;else if(x==3)return 3;else if(x==2)return 1;return 0;}int main(){#ifdef zsc freopen("input.txt","r",stdin);#endifint n,i,j,u,v;while(~scanf(" %d",&n)){fill(col,col+T,0);fill(row,row+T,0);for(i=0;i<n;++i){for(j=0;j<n;++j){scanf("\n%c",&s[i][j]);if(s[i][j]=='C')col[j]++,row[i]++;}}if(n==1){printf("0\n");continue;}ll ma=0;for(i=0;i<n;++i){ma += fun(col[i])+fun(row[i]);}printf("%I64d\n",ma);} return 0;}
- Codeforces Round #343 (Div. 2) -A. Far Relative’s Birthday Cake(组合+模拟)
- Codeforces Round #343 (Div. 2) Far Relative’s Birthday Cake
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake
- CodeForces 629 A. Far Relative’s Birthday Cake(水~)
- CodeForces 629A Far Relative’s Birthday Cake(组合数,水题)
- Codeforces--629A--Far Relative’s Birthday Cake(暴力模拟)
- Codeforces 629A Far Relative’s Birthday Cake
- CodeForces 629A Far Relative’s Birthday Cake
- CodeForces 629A Far Relative’s Birthday Cake
- CodeForces-629A-Far Relative’s Birthday Cake
- A. Far Relative’s Birthday Cake
- 629A.Far Relative’s Birthday Cake
- A. Far Relative’s Birthday Cake【排列组合】
- Codeforces Round #343 (Div. 2) -B. Far Relative’s Problem(模拟)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
- Coderforces 629A Far Relative’s Birthday Cake 【水题】
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem (贪心)
- Android进程间通信(IPC)机制Binder简要介绍和学习plan
- fluxcapacitor 安装
- Android中糟糕的AsyncTask
- java 对象的内存分配和回收
- Move Zeroes---283
- Codeforces Round #343 (Div. 2) -A. Far Relative’s Birthday Cake(组合+模拟)
- margin的解析逻辑
- Android基础-Notification用法
- 网上能搜出来的拦截短信功能的都是用abortBroadcast()。。。 4.3+这方法就没暖用了
- 软件推荐书籍
- Innodb逻辑存储机制
- webRTC进阶-概览-之一:WebRTC 会议的组网技术对比与分析
- 织梦去掉后台登录验证码
- 基于注解的Spring AOP的配置和使用--转载