SP5464 CT - Counting triangles 题解】的更多相关文章

Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, program to count how many triangles in it. Input The length n (n <= 500) of theequilateral triangle's side, one per line. process to the end of the fil…
Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2506    Accepted Submission(s): 1184 Problem Description Given an equilateral triangle with n the length of its side, program t…
题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对于两点,求他们的gcd - 1,得到的就是他们之间有多少个点,那么情况数就能够求了,然后还是利用容斥原理去计数,然后累加出答案 代码: #include <stdio.h> #include <string.h> #include <algorithm> using nam…
1307 - Counting Triangles    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are given N sticks having distinct lengths; you have to form some triangles using the sticks. A triangle is valid if its area is positive. You…
如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单:m*n的方格,其格点是(m+1)*(n+1)的点阵,选三个点有C((m+1)*(n+1), 3)中情况,其中能构成三角形的不容易计算,所以计算它的反面:三个点不能构成三角形,即三点共线的情况. 三点共线的情况也可以再分为三类: ①三点在一条水平线上,共有m*C(n+1, 3)种情况. ②三点在一条竖…
Chef and The Right Triangles The Chef is given a list of N triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane. His job is to figure out how many of the given triangles are right triangles. A right…
题目描述 定义 \(d(n)\) 为 \(n\) 的正因数的个数,比如 \(d(2) = 2, d(6) = 4\). 令 $ S_1(n) = \sum_{i=1}^n d(i) $ 给定 \(n\),求 \(S_1(n)\). 输入格式 第一行包含一个正整数 \(T\) (\(T \leq 10^5\)),表示数据组数. 接下来的 \(T\) 行,每行包含一个正整数 \(n\) (\(n < 2^{63}\)). 输出格式 对于每个 \(n\),输出一行一个整数,表示 \(S_1(n)\)…
题目链接:https://www.hackerrank.com/contests/codestorm/challenges/ilia 这周六玩了一天的Codestorm,这个题目是真的很好玩,无奈只做出了四道题,自己太菜,difficult的题目一道题都没出,把moderate的题目拿出来总结一下吧. 给了一些棍子,每根棍子的长度各不相同,然后问这些棍子组成的锐角三角形的个数.直角三角形的个数.钝角三角形的个数. 思路很明显,枚举前面两根木棒的长度,然后二分第三根木棒的长度.复杂度O(n^2lo…
第一道 A 掉的严格意义上的组合计数题,特来纪念一发. 第一次真正接触到这种类型的题,给人感觉好像思维得很发散才行-- 对于一个排列 \(p_1,p_2,\dots,p_n\),对于每个 \(i\) 向 \(p_i\) 连一条边,可以发现整个构成了一个由若干环组成的图,目标是将这些环变为自环. 引理:把长度为 \(n\) 的环变为 \(n\) 个自环,最少交换次数为 \(n-1\). 用归纳法证,对于当前情况,任意一次交换都将其拆为两个环,由淘汰赛法则可知引理成立. 记 \(F_n\) 表示在最…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1296 题意:给出一个a*b的网格,在网格上取不共线的三点构成三角形,求三角形总数.分析:就是一一道简单的组合数计算题目,设总结点数为n,则取三个节点的个数为C(n,3), 然后减去横向.竖向.斜向的三点共线的个数即可,斜线三点共线等价于所枚举的矩形的长宽成倍数关系,…