UVA 11401 - Triangle CountingTriangle Counting 数学
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
at least 1 pair of arms with different length.
Input
The input for each case will have only a single positive integer n (3 ≤ n ≤ 1000000). The end of input
will be indicated by a case with n < 3. This case should not be processed.
Output
For each test case, print the number of distinct triangles you can make.
Sample Input
5
8
0
Sample Output
3
22
题意:问你从1......n中任意选择三个数,能形成三角形的方案数
题解:我是递推 假设已经找出 从前i个数找到的方案数, 那么dp[i] = dp[i-1] + i与前面的数形成的方案
根据排列组合计算可以得到
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = +;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ; ll dp[N],c[N][];
ll n,tmp,tmpp;
void init() {
c[][] = ;c[][] = ;
for(int i=;i<N;i++) {
c[i][] = i;
c[i][] = c[i-][] + c[i-][];
}
dp[] = ;
for(int i=;i<N;i++) {
tmp = i%?i/+:i/;
tmpp = (tmp-)*(tmp-)/;
dp[i] = dp[i-] + c[i - tmp][] + tmpp;
}
}
int main() {
init();
while(~scanf("%lld",&n)!=EOF) {
if(n<) break;
printf("%lld\n",dp[n]);
}
return ;
}
代码
UVA 11401 - Triangle CountingTriangle Counting 数学的更多相关文章
- uva 11401 Triangle Counting
		
// uva 11401 Triangle Counting // // 题目大意: // // 求n范围内,任意选三个不同的数,能组成三角形的个数 // // 解题方法: // // 我们设三角巷的 ...
 - 【递推】【组合计数】UVA - 11401 - Triangle Counting
		
http://blog.csdn.net/highacm/article/details/8629173 题目大意:计算从1,2,3,...,n中选出3个不同的整数,使得以它们为边长可以构成三角形的个 ...
 - UVa 11401 Triangle Counting (计数DP)
		
题意:给定一个数 n,从1-n这些数中任意挑出3个数,能组成三角形的数目. 析:dp[i] 表示从1-i 个中任意挑出3个数,能组成三角形的数目. 代码如下: #pragma comment(link ...
 - 【UVA 11401】Triangle Counting
		
题 题意 求1到n长度的n根棍子(3≤n≤1000000)能组成多少不同三角形. 分析 我看大家的递推公式都是 a[i]=a[i-1]+ ((i-1)*(i-2)/2-(i-1)/2)/2; 以i 为 ...
 - Triangle Counting UVA - 11401(递推)
		
大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long ...
 - UVa 12230 - Crossing Rivers(数学期望)
		
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
 - Uva 11401 数三角形
		
题目链接:https://uva.onlinejudge.org/external/114/11401.pdf 题意:1~n个数里面挑3个不同的数,组成一个三角形.求方案数. 分析: 令最长的边为X, ...
 - uva 11401
		
Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of length 1, 2… ...
 - UVA&&POJ离散概率与数学期望入门练习[4]
		
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
 
随机推荐
- JavaScript高级程序设计之数值数组排序
			
如果数组中全是Nunber类型,则可以按照数值大小排序 , , , , ]; // asc升序函数 function compareAsc(value1, value2) { if (value1 & ...
 - golang反射初试
			
golang反射来自Go AST(Abstract Syntax Tree). reflect操作更多像traverse AST. t := reflect.TypeOf(obj) 使用TypeOf( ...
 - HTML5七大优势“逼宫”APP
			
HTML5颠覆了PC互联网的格局,优化了移动互联网的体验,接下来几年,HTML5将颠覆原生App世界. 跨平台: 在多屏年代,开发者的痛苦指数非常高,人人都期盼HTML5能扮演救星.多套代码.不同技术 ...
 - mysql取整,小数点处理函数floor(), round()
			
mysql数值处理函数floor与round 在mysql中,当处理数值时,会用到数值处理函数,如有一个float型数值2.13,你想只要整数2,那就需要下面的函数floor与round. ...
 - 关于开始学习Leetcode的第一帖
			
从明天开始,白天在实验室完成工作,晚上来图书馆换个环境去学习算法数据结构等计算机基础性的技能.在LeetCode这个平台上做题. 现在感觉自己在算法和数据机构这方面实在是太薄弱了,需要慢慢的捡起来来, ...
 - MVC4.0 利用IActionFilter实现单一Action返回多种结果
			
延续MVC4.0 实现单一Action返回多种结果,我们实现了在一个Action中根据前台请求方式的不同和请求内容的不同返回了多个结果,但是这种返回多个结果的业务逻辑并不通用.如果现在年纪Action ...
 - MyEclipse查看Struts2源码及Javadoc文档
			
一.查看Struts2源码 1.Referenced Libraries >struts2-core-2.1.6.jar>右击>properties. 2.Java Source A ...
 - 团队开发——第一篇scrum报告
			
一.角色介绍 产品负责人(兼项目经理PM):王雪青 scrum master: 陆宇 开发团队:赵建松.张文冬.徐擎天 二.product backlog 1.买家登录后,显示各个小吃摊的信息,主要是 ...
 - Mac系统如何配置adb
			
在使用mac进行android开发之前,我们一般会安装android studio 或者 eclipse,无论哪一款开发软件,都少不了安装adb(Android Debug Bridge).adb(A ...
 - Shell常用操作
			
1.读取配置文件中的jdbc_url参数的值($InputParamFile为待读取的目标文件绝对路径) jdbc_url=`grep "jdbc_url" $InputParam ...