uva 11401 Triangle Counting
// 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的更多相关文章
- 【递推】【组合计数】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 CountingTriangle Counting 数学
You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. ...
- [Usaco2010 OPen]Triangle Counting 数三角形
[Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 394 Solved: 1 ...
- acdream.A Very Easy Triangle Counting Game(数学推导)
A - A Very Easy Triangle Counting Game Time Limit:1000MS Memory Limit:64000KB 64bit IO Forma ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥
1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 272 Sol ...
- bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和
[Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 526 Solved: 2 ...
- 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] ...
随机推荐
- JS获取指定的cookie值
cookie Name为TEST_COOKIE:用如下方法可以获取cookie值: document.cookie.replace(/(?:(?:^|.*;\s*)TEST_COOKIE\s*\=\s ...
- socket网络通信
1.socket通常也称作"套接字",用于描述IP地址和端口.在internet上的主机一般运行了多个服务软件,同时提供几种服务,每种服务都打开一个socket,并绑定到一个端口上 ...
- JavaWeb---通过ServletConfig获取Servlet的初始化参数
package com.zyz; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import j ...
- PTA Strongly Connected Components
Write a program to find the strongly connected components in a digraph. Format of functions: void St ...
- PTA Insertion or Heap Sort
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- javascript按中文首字母排序
resultValue=[ '武汉' , '北京' , '上海' , '天津' ] ; resultValue= resultValue.sort( function compareFunction( ...
- 利用Jurassic在.net下运行js函数
static void Main(string[] args) { var eng = new Jurassic.ScriptEngine(); eng.Evaluate("function ...
- ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes.
ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes. 这是因为在过程中用到了dbms_output.put_line()在服务器端输出信 ...
- Logstash 安装与配置
一.Logstash 描述 简单而又强大的数据抽取与处理工具,相比于flums一整本书的描述强大而又好用. 还记得我13年用python写了一个数据抽取.校验工具,设计思路也同样是拆解处理过程模板,然 ...
- 【如何快速的开发一个完整的iOS直播app】(原理篇)
原文转自:袁峥Seemygo 感谢分享.自我学习 目录 [如何快速的开发一个完整的iOS直播app](原理篇) [如何快速的开发一个完整的iOS直播app](播放篇) [如何快速的开发一个完整的 ...