//    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) / 2
// 而这个时候当y>x/2的时候就有 y = z的时候,所以要减去相等的
// 情况 y 从 x/2 + 1 .... x - 1一共 x - 1 - x/2.最后,这样
// y和z可以互换的,所以计算了两次,要再/2,最后的最后累加就好了
//
// 感悟:
//
// 这道题,我开始真的没想到,不会哟,实在是想不到,太巧了,想了好久
// 继续加油吧~~~~FIGHTING #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; typedef long long ll; ll f[]; void init(){
f[] = ;
for (ll i=;i<=;i++){
f[i] = f[i-] + ((i - ) * (i-) / - (i-- i/)) / ;
}
} int main(){
init();
int n;
while(cin>>n){
if (n < )
break;
cout << f[n] << endl;
}
}

uva 11401 Triangle Counting的更多相关文章

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

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

  2. UVa 11401 Triangle Counting (计数DP)

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

  3. 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. ...

  4. [Usaco2010 OPen]Triangle Counting 数三角形

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 394  Solved: 1 ...

  5. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  6. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  7. bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥

    1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 272  Sol ...

  8. bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 526  Solved: 2 ...

  9. UVA 1640 The Counting Problem UVA1640 求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数。

    /** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a] ...

随机推荐

  1. 【Python全栈笔记】03 [模块二] 16-17 Oct Set 集合,三目运算

    Set 集合 set - unordered collections of unique elements 创建一个set/一个空set # create a new set set1 = {1,2, ...

  2. linux命令(8):cp 命令

    cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...

  3. Android多线程编程之AsyncTask

    进程?线程? 进程是并发执行的程序在执行过程中分配和管理资源的基本单位,是一个动态的概念.每个进程都有自己的地址空间(进程空间).进程空间的大小与处理机位数有关.进程至少有5种基本状态:初始态,执行态 ...

  4. Light OJ 1030 - Discovering Gold(概率dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...

  5. jQuery Mobile 表单基础

    jQuery Mobile 会自动为 HTML 表单添加优异的便于触控的外观. jQuery Mobile 表单结构 jQuery Mobile 使用 CSS 来设置 HTML 表单元素的样式,以使其 ...

  6. Object.create()方法的低版本兼容问题

    Object.prototype.create=(function(){ if(Object.prototype.create){return Object.prototype.create}else ...

  7. 如何在Mac OS X中显示隐藏的文件

    打开终端,输入: defaults write com.apple.finder AppleShowAllFiles -bool true 显示文件夹中的隐藏文件. defaults write co ...

  8. 使用angularJS遇见的一些问题的解决方案

    1. angularJS的$http.post请求,SpringMVC后台接收不到参数值的解决方案 问题一般为:400 Required String parameter 'rPassword' is ...

  9. The different between ng-grid & ui-grid

    ui-grid is replacing ng-grid, and support for ng-grid is getting thin as most of the original (2.x) ...

  10. keepalived高可用

    keepalived介绍 Keepalived是一个基于vrrp协议的高可用方案,vrrp协议的软件实现,原生设计的目的为了高可用ipvs服务. 1. vrrp协议 VRRP是一种容错协议,它通过把几 ...