UVA 12075 Counting Triangles】的更多相关文章

题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对于两点,求他们的gcd - 1,得到的就是他们之间有多少个点,那么情况数就能够求了,然后还是利用容斥原理去计数,然后累加出答案 代码: #include <stdio.h> #include <string.h> #include <algorithm> using nam…
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1296 动态规划 我们先计算任意三个点组成的可能,然后排除同一水平,同一垂直的,同一斜线的,前两个比较好计算,同一斜线的稍复杂.要用容斥原理,首先我们动手计算一下,可能发现每次多的是gcd(i, j)-1,然后再去重,dp[i][j]代表从左上角[0,0] 到这个点[i,j]并…
先看第一题,有n*m个点,求在这些点中,有多少条直线,经过了至少两点,且不是水平的也不是竖直的. 分析:由于对称性,我们只要求一个方向的线即可.该题分成两个过程,第一个过程是求出n*m的矩形中,dp[i][j]代表在这个矩形中终点是到(i,j)这个点的满足题意的直线条数,那么,用dp的话就可以得出递推关系:由长和宽分别小1的左右两个矩形中满足题意的线的条数减去他们共有的矩形中满足的线的条数(容斥减去重复部分),之后还要判断从最左上角的点(1,1)到(i,j)是否可以组成一条线,这个条件是gcd(…
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…
题目链接:uva 1436 - Counting heaps 题目大意:给出一个树的形状,如今为这棵树标号,保证根节点的标号值比子节点的标号值大,问有多少种标号树. 解题思路:和村名排队的思路是一仅仅的uva11174,最后问题仅仅和树德结构有直接关系.f(root)=(s(root)−1)!(s(1)∗s(2)∗⋯∗s(n) 可是给定的取模数不是质数.所以不能用逆元做.仅仅能将分子分母分别拆分成质因子,然后对质因子进制约分.由于最后的答案一定是正整数,所以对于每一个质因子,分子分解出的因子个数…
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…
Counting The Problem Gustavo knows how to count, but he is now learning how write numbers. As he is a very good student, he already learned 1, 2, 3 and 4. But he didn't realize yet that 4 is different than 1, so he thinks that 4 is another way to wri…
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3Seconds   Given n points on the XY plane, count how many regular rectanglesare formed. A rectangle is regular if and only if its sides are all paralle…
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保存这些边两点的y坐标y1, y2.之后把这些边按y1排序,再按y2排序.用O(n)的方法找出有几个连续的y1, y2都相等.那么这些边两两是能构成矩形的.为C2cnt种.然后累加起来就是答案 代码: #include <stdio.h> #include <string.h> #inc…
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2250 判断两个空间中的三角形是否有公共点. 代码如下: #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <iostream> #in…
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.InputThe first line contains the number of tests t (1 ≤ t ≤ 10). Each case contains a single lin…
如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单:m*n的方格,其格点是(m+1)*(n+1)的点阵,选三个点有C((m+1)*(n+1), 3)中情况,其中能构成三角形的不容易计算,所以计算它的反面:三个点不能构成三角形,即三点共线的情况. 三点共线的情况也可以再分为三类: ①三点在一条水平线上,共有m*C(n+1, 3)种情况. ②三点在一条竖…
题意:三维空间中,给出两个三角形的左边,问是否相交. 面积法判断点在三角形内: #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<memory.h> #include<cstdlib> #include<vector> #define clc(a,b) memset…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1296 题意:给出一个a*b的网格,在网格上取不共线的三点构成三角形,求三角形总数.分析:就是一一道简单的组合数计算题目,设总结点数为n,则取三个节点的个数为C(n,3), 然后减去横向.竖向.斜向的三点共线的个数即可,斜线三点共线等价于所枚举的矩形的长宽成倍数关系,…
这两个题的模型是有n个人,有若干的关系表示谁是谁的父亲,让他们进行排队,且父亲必须排在儿子前面(不一定相邻).求排列数. 我们假设s[i]是i这个节点,他们一家子的总个数(或者换句话说,等于他的子孙数+1(1是他本身)),f[i]是以i为根的节点的排列种数.那么总的种数为n!/(s[1]+s[2]+...+s[n]).关于这个递推式的得出,是根据排列公式的,我们假设一个例子,不妨设4.5是2的子孙,3是1的子孙.那么他们进行排队的话,不妨看成222和11排队就是2的家族和1的家族排队(2和1是平…
题目链接:https://www.hackerrank.com/contests/codestorm/challenges/ilia 这周六玩了一天的Codestorm,这个题目是真的很好玩,无奈只做出了四道题,自己太菜,difficult的题目一道题都没出,把moderate的题目拿出来总结一下吧. 给了一些棍子,每根棍子的长度各不相同,然后问这些棍子组成的锐角三角形的个数.直角三角形的个数.钝角三角形的个数. 思路很明显,枚举前面两根木棒的长度,然后二分第三根木棒的长度.复杂度O(n^2lo…
Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1882    Accepted Submission(s): 898 Problem Description Given an equilateral triangle with n the length of its side, program to…
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY…
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116…
// uva 11401 Triangle Counting // // 题目大意: // // 求n范围内,任意选三个不同的数,能组成三角形的个数 // // 解题方法: // // 我们设三角巷的最长的长度是c(x),另外两边为y,z // 则由z + y > x得, x - y < z < x 当y = 1时,无解 // 当y = 2时,一个解,这样到y = x - 1 时 有 x - 2个 // 解,所以一共是0,1,2,3....x - 2,一共(x - 2) * (x - 1…
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现的次数,先将cnt初始化为0,接着让i从1枚举到n, 对每个i,处理以活的i的每一个位置上的数,并在相应的cnt下标上+1 最后输出cnt数组即可 /* UVa 1225 Digit Counting --- 水题 */ #include <cstdio> #include <cstring…
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/35244875 题目链接:uva 12508 - Triangles in the Grid 题目大意:给出n,m.A和B.要求计算在(n+1)∗(m+1)的矩阵上.能够找出多少个三角形,面积在AB之间. 解题思路:首先枚举矩阵.然后计算有多少个三角形以该矩阵为外接矩阵.而且要满足体积在AB之间.然后对于每一个矩阵,要确定在大的范围内能够确定几…
/** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数. 思路:数位dp: dp[leadzero][i][j][k]表示前面是否选过非0数,即i长度之后可以第一个出现0,而不是前导0,长度为i,前面出现j,k次,j出现的次数. */ #include<iostream> #include<cstri…
Triangle Counting Time limit1000 ms Description You are given n rods of length 1, 2-, n. You have to pick any 3 of them and build a triangle. How many distinct triangles can you make? Note that, two triangles will be considered different if they have…
You will be given N points on a circle. You must write a program to determine how many distinctequilateral triangles can be constructed using the given points as vertices.The gure below illustrates an example: (a) shows a set of points, determined by…
You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. Howmany distinct triangles can you make? Note that, two triangles will be considered different if they haveat least 1 pair of arms with different length…
题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以分块的时候要多分几种情况. 以2345为例,这是一个四位数,首先要计算一下所有的一位数.两位数以及三位数各个数字出现的个数. 对应的模板分别为n,n*,n**,其中n代表非零数字,*代表任意数字. 考虑这样一个长为l的模板****(l个*),这样的数共10l个,而且各个数字都是等频率出现,所以每个数…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4515 题意: 给出整数a.b,统计a和b(包含a和b)之间的整数中,数字0,1,2,3,4,5,6,7,8,9分别出现了多少次.1≤a,b≤1e8. 分析: 解决这类题目的第一步一般都是:令f(n,d)表示0-n中数字d出现的次数,则所求的就是f(b,d)-f(a-1,d).例如,…
12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的个数减去[0,B]的个数就是答案,然后对于每一个子矩阵个数非常好求为(n−r+1)∗(m−c+1). 关键在于怎么求每一个子矩阵的符合个数. 想了好久,參考别人题解才想出来.分3种情况讨论: 1.一个点在矩形顶点.另外两点相应在顶点的另外两边上. 2.两个点在顶点上.另外一点在对边上. 3.三个点都…