uva11401:Triangle Counting 递推 数学
uva11401:Triangle Counting
题目读不清楚的下场就是多做两个小时...从1-n中任选3个不重复数字(不重复啊!!坑爹啊!)问能组成三角形的有多少个,
显然1~n能组成的三角形集合肯定包括了1~n-1所能组成的三角形,所以假如have[i-1]为1~n-1组成的三角形数目,have[i]只要计算:含有长度为n的边的三角形数目+have[i-1] 就行了
然后分一下类就行了,1~n/2为一块,n/2+1~n为一块,因为有一条边必须为n,剩下两条边要么都在第二块,要么分别在第一第二块,在把n分奇偶讨论下很容易就得到公式了
#include <iostream>
#include <string.h>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h> #define SIGMA_SIZE 26
#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
//typedef unsigned long long uLL; inline LL LMax(LL a,LL b) { return a>b?a:b; }
inline LL LMin(LL a,LL b) { return a>b?b:a; }
inline int Max(int a,int b) { return a>b?a:b; }
inline int Min(int a,int b) { return a>b?b:a; }
inline int gcd( int a, int b ) { return b==?a:gcd(b,a%b); }
inline int lcm( int a, int b ) { return a/gcd(a,b)*b; } //a*b = gcd*lcm
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = ;
const int maxk = ;
const int maxn = 1e6+; int num[maxn];
LL have[maxn]; void init()
{
//have[1] = 1; have[2] = 2;
bool test = true; //true表示奇数,false表示偶数 have[] = ;
LL tmp;
for ( LL i = ; i <= (LL)1e6; i++ )
{
LL t = i/;
if (!test)
{
have[i] = t*(t-) + have[i-];
test = !test;
}
else
{
have[i] = (t-)*(t-) + have[i-];
test = !test;
}
}
} int main()
{
init(); int x; while ( ~scanf("%d", &x) && x >= )
printf( "%lld\n", have[x] );
return ;
}
uva11401:Triangle Counting 递推 数学的更多相关文章
- Leetcode 118 Pascal's Triangle 数论递推
杨辉三角,即组合数 递推 class Solution { vector<vector<int>> v; public: Solution() { ; i < ; ++i ...
- UVA11401 Triangle Counting
题意 输入\(n\),输出有多少种方法可以从\(1,2,3,\dots,n\)中选出3个不同的整数,使得以他们为三边长可以组成三角形. \(n \leq 10^6\) 分析 参照刘汝佳的题解. 按最大 ...
- Luogu P2327 [SCOI2005]扫雷【递推/数学】By cellur925
题目传送门 推了好久啊.看来以后要多玩扫雷了qwq. 其实本题只有三种答案:0.1.2. 对于所有第一列,只要第一个数和第二个数确定后,其实整个数列就确定了,我们可以通过这个递推式得出 sec[i-] ...
- Acwing-98-分形之城(递推,数学)
链接: https://www.acwing.com/problem/content/description/100/ 题意: 城市的规划在城市建设中是个大问题. 不幸的是,很多城市在开始建设的时候并 ...
- POJ1850-Code 递推数学
题目链接:http://poj.org/problem?id=1850 题目大意: 按照字典序对升序排列组成的字母进行编号,给出一个长度不超过10的串,求出它的编号是多少?如果无法进行编号则输出0. ...
- Number Sequence POJ - 1019 递推 数学
题意 1 12 123 1234 12345 ....这样的序列 问第n位数字是几 是数字! 1-9! 思路:递推关系 主要是位数的计算 用a[i]=a[i-1]+(int)log10((do ...
- acdream.A Very Easy Triangle Counting Game(数学推导)
A - A Very Easy Triangle Counting Game Time Limit:1000MS Memory Limit:64000KB 64bit IO Forma ...
- CJOJ 1331 【HNOI2011】数学作业 / Luogu 3216 【HNOI2011】数学作业 / HYSBZ 2326 数学作业(递推,矩阵)
CJOJ 1331 [HNOI2011]数学作业 / Luogu 3216 [HNOI2011]数学作业 / HYSBZ 2326 数学作业(递推,矩阵) Description 小 C 数学成绩优异 ...
- 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】
Pokémon GO Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- Linux文本编辑命令
sort 排序工具,比较排序(根据字典排序) -t 指定分隔符(默认是空格) -k 指定第几域排序(默认第一域) -n 以数字大小排序 -r 逆向排序 -v 去掉重复行 -o 输出到文件中 -c 测试 ...
- AbstractByteBuf 源码分析
主要成员变量 static final ResourceLeakDetector<ByteBuf> leakDetector = new ResourceLeakDetector<B ...
- nodejs入门最简单例子
一.mac话,先安装nodejs环境: brew install nodejs 二.先写一个main.js var http = require("http"); http.cre ...
- JS数组 谁是团里成员(数组赋值)var myarray = new Array(66,80,90,77,59);//创建数组同时赋值
谁是团里成员(数组赋值) 数组创建好,接下来我们为数组赋值.我们把数组看似旅游团的大巴车,大巴车里有很多位置,每个位置都有一个号码,顾客要坐在哪个位置呢? 第一步:组个大巴车 第二步:按票对号入座 大 ...
- db.Database.SqlQuery完成分页封装
调用代码: string sql = @"SELECT a.Id ,c.Title,a.Content,a.Status,b.ReportSum FROM dbo.Comment AS a ...
- 关于spring java.lang.IllegalArgumentException: Name for argument type [java.lang.String] 的错误
况描述: web工程在windows环境eclipse下编译部署没有问题,系统升级时需要运维从Git取相应的源码并编译部署到线上机器,部署启动正常没有错误,当访问业务的action时报错,如下. 错误 ...
- js获取json的健与值
let myObj = { name: '张三', age: 18,sex:'女' } let tempArr = Object.keys(myObj) console.log(tempArr) fo ...
- Java实现RSA加密
末尾贴上代码↓↓↓↓↓↓↓↓↓↓↓↓ 1.原理 2.实现过程 3. 公式 4.举例 p=13, q=11 , (p,q互质) N=p*q=143 L=(p-1)*(q-1)=120 E=7 ...
- 19-10-28-A
竟然?竟然?竟然? 我已经用了半个键盘的编号了$\text{T_T}$ $\mathbb{AFO}$感稍强 h1是不是有点大? ZJ+TJ: T1 以为是什么数据结垢,但是是个链表. 所以可以使用 v ...
- Consul 集群搭建
搭建集群:.启动node1机器上的Consul (node1机器上执行) consul agent -data-dir /tmp/node1 -node=node1 -bind=192.168.0.1 ...