//    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. WizNote for linux installation

    源一:没有用处 官网链接http://www.wiznote.com/download-wiznote-for-Linux. 源二:提供了源及安装方法 Fedora 中文社区软件源,具体位置在这里. ...

  2. Struts2理解--动态方法和method属性及通配符_默认Action

    众所周知,默认条件下,在浏览器输入indexAction!execute.action,便会执行indexAction类里的execute方法,这样虽然方便,但可能带来安全隐患,通过url可以执行Ac ...

  3. 为什么重写equals时必须重写hashCode方法?

    原文地址:http://www.cnblogs.com/shenliang123/archive/2012/04/16/2452206.html 首先我们先来看下String类的源码:可以发现Stri ...

  4. Html登录表单阻止自动填充

    设置属性 autocomplete="off" 阻止浏览器从cache获取数据填充登录表单. <input type="text" name=" ...

  5. jQuery Mobile 图标

    jQuery 图标 如需在 jQuery Mobile 中向按钮添加图标,请使用 data-icon 属性: <a href="#anylink" data-role=&qu ...

  6. 计算软键盘的高度然后确定自定义的View的具体位置

    singleTouchView.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayout ...

  7. sk_buff封装和解封装网络数据包的过程详解(转载)

    http://dog250.blog.51cto.com/2466061/1612791 可以说sk_buff结构体是Linux网络协议栈的核心中的核心,几乎所有的操作都是围绕sk_buff这个结构体 ...

  8. asp.net mvc 自定义身份验证 2

    控制成员角色 [Authorize(Rroles="Administator,SuperAdmin")] public class StoreManagerController:C ...

  9. TCP/IP详解系列 --- 概念总结01

    UDP协议  .vs.  TCP协议:  原理上:(TCP报文段. vs . UDP用户数据报) TCP协议的特性: TCP是面向连接的运输层协议,应用程序在使用TCP协议之前,必须先建立TCP连接. ...

  10. My安卓知识1--SQLite数据库

    前一阵子做了一个小项目,关于android的,想记录一下学到的一些知识,做成一个小系列吧,算是对自己这一个多月来的见证.首先说明,这些知识也都是从网上各处学习来的,我自己做了一些小整理. 1.SQLi ...