Right Triangles

2024-08-27 23:18
文章标签 triangles right

本文主要是介绍Right Triangles,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

H - Right Triangles
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 52B

Description

You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).

Input

The first line contains two positive integer numbers n and m (1 ≤ n, m ≤ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.

Output

Output a single number — total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Sample Input

Input
2 2
**
*.
Output
1
Input
3 4
*..*
.**.
*.**
Output
9
 
#include<stdio.h>
#include<string.h> 
int main()
{int n,m,i,j,r[1011],c[1011];__int64 s,t;char a[1011][1011];while(~scanf("%d%d",&n,&m)){s=t=0;memset(r,0,sizeof(r));memset(c,0,sizeof(c));for(i=0;i<n;i++){scanf("%s",a[i]);for(j=0;j<m;j++)if(a[i][j]=='*'){r[i]++;c[j]++;}}for(i=0;i<n;i++){s=0;for(j=0;j<m;j++)if(a[i][j]=='*')s+=c[j]-1;t+=s*(r[i]-1);}printf("%I64d\n",t);}
}


这篇关于Right Triangles的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1113066

相关文章

MySQL 多表连接操作方法(INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL OUTER JOIN)

《MySQL多表连接操作方法(INNERJOIN、LEFTJOIN、RIGHTJOIN、FULLOUTERJOIN)》多表连接是一种将两个或多个表中的数据组合在一起的SQL操作,通过连接,... 目录一、 什么是多表连接?二、 mysql 支持的连接类型三、 多表连接的语法四、实战示例 数据准备五、连接的性

Csting Left Mid Right

 CString Left( int nCount ) const;                   //从左边1开始获取前 nCount 个字符 CString Mid( int nFirst ) const;                      //从左边第 nCount+1 个字符开始,获取后面所有的字符 CString Mid( int nFirst, int nC

join连接的五种方式的简单使用案例(Inner join,Left join,Right join,Full join,Cross join)

1.内连接Inner join 内连接是基于连接谓词将俩张表(如A和B)的列组合到一起产生新的结果表  ,在表中存在至少一个匹配时,INNER JOIN 关键字返回行。    下面是一个简单的使用案例  以下是运行代码及结果  2.左外连接Left join 左外连接Left join关键字会从左表那里返回所有的行,即使是在右表中没有匹配到的行    下面是一个简单的案例

Leetcode211: Populating Next Right Pointers in Each Node II

Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant e

解决CSS布局中padding-right不生效问题

.list_scroller {position: relative;padding-left: 32rpx;padding-right: 32rpx;padding-bottom: 226rpx;} // 解决方法: 因为默认content-box,width:100%是不包含padding的,但实际我们想包含padding。 box-sizing: border-box;

left join 、right join 等各种连接方式的区别

(几种连接有时候经常搞混,这里小记一下留作备忘)   SQL提供了多种类型的连接方式,它们之间的区别在于: 从相互交叠的不同数据集合中选择用于连接的行时所采用的方法不同。 连接类型          定义 内连接            只连接匹配的行 左外连接          包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行

left join、right join

总结 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录  right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) 只返回两个表中联结字段相等的行 属于外部连接 举例如下:  -------------------------------------------- 表A记录如下:

Binary Tree Right Side View

Notes:站在右边看,即层次遍历,只保存每一层的最后一个值! /*** Definition for binary tree* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/public class S

Binary Tree Right Side View问题及解法

问题描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. 示例: Given the following binary tree, 1

【PAT】【Advanced Level】1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a non-negative integer N, your task is to compute the sum of all the