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 数学的更多相关文章

  1. uva 11401 Triangle Counting

    // uva 11401 Triangle Counting // // 题目大意: // // 求n范围内,任意选三个不同的数,能组成三角形的个数 // // 解题方法: // // 我们设三角巷的 ...

  2. 【递推】【组合计数】UVA - 11401 - Triangle Counting

    http://blog.csdn.net/highacm/article/details/8629173 题目大意:计算从1,2,3,...,n中选出3个不同的整数,使得以它们为边长可以构成三角形的个 ...

  3. UVa 11401 Triangle Counting (计数DP)

    题意:给定一个数 n,从1-n这些数中任意挑出3个数,能组成三角形的数目. 析:dp[i] 表示从1-i 个中任意挑出3个数,能组成三角形的数目. 代码如下: #pragma comment(link ...

  4. 【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 为 ...

  5. Triangle Counting UVA - 11401(递推)

    大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long ...

  6. UVa 12230 - Crossing Rivers(数学期望)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. Uva 11401 数三角形

    题目链接:https://uva.onlinejudge.org/external/114/11401.pdf 题意:1~n个数里面挑3个不同的数,组成一个三角形.求方案数. 分析: 令最长的边为X, ...

  8. uva 11401

    Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of length 1, 2… ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. Linux开机启动程序详解

    Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...

  2. Objective-C编码规范

    参考 http://www.csdn.net/article/2015-06-01/2824818-objective-c-style-guide/1 介绍 我们制定Objective-C编码规范的原 ...

  3. iOS下日期的处理

    NSDate存储的是世界标准时(UTC),输出时需要根据时区转换为本地时间 Dates         NSDate类提供了创建date,比较date以及计算两个date之间间隔的功能.Date对象是 ...

  4. 数据库的编码浅谈(ZHS16GBK与US7ASCII)

     数据库的编码浅谈(ZHS16GBK与US7ASCII) 2007-11-15 17:14:18 分类: Oracle SQL> SELECT RAWTOHEX('郭A军') from dual ...

  5. OC中成员变量的命名

    先前写C++ 的时候,命名成员变量一般都是用 m_veriableName:的方式,但是进到新项目组,用了OC以后,发现成员变量都是用 veriableName_的方式,最后的一个下划线表示是成员变量 ...

  6. js之变量和作用域

    JS的变量和其他语言的变量有很大区别.JS变量时“松散型”的,决定它只是在特定时间用于保存特定的一个名字而已.由于不存在变量要保存何种数据类型,变量的值和其数据类型可以在脚本的生命周期内改变. JS两 ...

  7. Android -- 与WEB交互在同一个会话Session中通信

    Session与Cookie Cookie和Session都为了用来保存状态信息,都是保存客户端状态的机制,它们都是为了解决HTTP无状态的问题而所做的努力. Session可以用Cookie来实现, ...

  8. CoffeeRobotTeam项目组报告

    一.小组分工 模块 任务 责任人 备注 报告 需求分析 熊振威 功能分析 熊振威 项目报告 熊振威 人机界面 秦勤.洪超 单元测试 姜进.张文强 机器人代码 机器人类 徐意.余拥军.孙智博 机器人运动 ...

  9. 向Array中添加选择排序

    选择排序思路 在无序区中选出最小的元素,然后将它和有序区的第一个元素交换位置. 选择排序实现 Function.prototype.method = function(name, func){ thi ...

  10. 1、android orm之greendao

    前提:最近写android项目,android自带数据库api有点复杂,于是偷懒用了greendao.greendao好处自己查,这里不赘述,但是零基础的的我用起来还是费了3天的功夫,取之于网络,特在 ...