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. android获取手机录

    在Android开发中,读取手机通讯录中的号码是一种基本操作,但是由于Android的版本众多,所以手机通讯录操作的代码比较纷杂,在本文中进行一下总结. Android1.5是现在的Android系统 ...

  2. windows下查看所有进程以及pid

    import ctypes import sys __metaclass__ = type class PROCESSENTRY32(ctypes.Structure): _fields_ = [ ( ...

  3. shell 编程基础

    1 创建shell脚本文件 要创建一个shell脚本文件,必须在第一行指定要使用的shell,其格式为: #! /bin/bash 接着加上该shell文件的注释,说明该脚本文件用来干什么,有谁创建, ...

  4. [转]开源中国的 IT 公司开源软件整理计划介绍

    [转]开源中国的 IT 公司开源软件整理计划介绍 http://www.oschina.net/news/61534/oschina-opensource-collection-plan-for-it ...

  5. 解决SQLite数据库中文乱码问题

      关于SQLite中出现中文乱码的分析以及解决方案 我们在使用SQLite数据库时候,可能会发现,向数据库插入数据时候显示的是汉字,但通过SQLite读出来时却显示的乱码,这是因为SQLite数据库 ...

  6. 查看BADI有哪些实现

    TCODE:SE18

  7. 配置 Cocoapods的简单配置及胡思乱想

    外部访问属性 & 重要属性变化 外部访问方法 监听方法 内部属性 swift编写 懒加载控件.布局.监听 使用第三方框架之前先需要配置 cocoapods环境 (唐巧博客) gib 查看自己的 ...

  8. word检视意见导出(VBA)

    Private Sub CommandButton1_Click() 'Dim Cmt As Comment Dim excelApp As Object Dim xlsWbk, objWdApp A ...

  9. 项目部署之VPN+端口映射

    背景:出差开发项目,需要在客户那里部署基本成型的系统.这套系统需要一个公网的ip地址(一个后台管理系统,使用花生壳提供域名服务.一个公网的tcp server,java io实现),但是客户那里无法提 ...

  10. 我是IT小小鸟

    我是IT小小鸟读后感 世界上没有一蹴而就的成功者,只有头悬梁锥刺股的奋斗者.蜉蝣向往大鹏的辉煌,却不曾知大鹏以往的汗水.蜉蝣之所以为蜉蝣,是因为它犹如井底之蛙,目光短浅,之盲目地羡慕成功者,而大鹏之所 ...