Rikka with wood sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 600    Accepted Submission(s): 169

Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta have a wood stick of length n which consists of n linked sticks of length 1. So it has n−1 connection points. Yuta finds that some sticks of length 1 of the wood stick are not strong. So he wants to choose three different connection points to cut it into four wood sticks and only one of them contains wood sticks which are not strong. And Yuta wants to minimize the length of this piece which contains bad wood sticks. Besides, Rikka wants to use the other three wood sticks to make a triangle. Now she wants to count the number of the ways to cut the wood sticks which can make both Yuta and herself happy.

It is too difficult for Rikka. Can you help her?

 
Input
This problem has multi test cases (no more than 20). For each test case, The first line contains two numbers n,m(1≤n≤1000000,1≤m≤1000). The next line contains m numbers (some of them may be same) – the position of each wood sticks which is not strong.
 
Output
For each test cases print only one number – the ways to cut the wood sticks.
 
Sample Input
6 1
3
5 1
3
 
Sample Output
2
0
 
Source
 #include<stdio.h>
#include<algorithm>
typedef __int64 ll ;
int n , m ;
int l , r ; bool ok (int a , int b , int c)
{
if (a + b > c && a + c > b && b + c > a)
return true ;
return false ;
} ll calc2 (int lg , int wd)
{
if (lg == wd) return ;
if (lg < wd) std::swap (lg , wd) ;
int x = (lg - wd)/ ;
if (x == ) x ++ ;
if (ok (x , lg - x , wd))
return lg - - (x - ) * ;
else
return lg - - x * ;
} ll calc1 (int lg)
{
ll tot = ;
for (int i = ; i <= lg/ ; i++) {
tot += calc2 (i , lg - i) ;
}
return tot ;
} int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d%d" , &n, &m)) {
l = n , r = ;
for (int i = ; i < m ; i++) {
int x ;
scanf ("%d" , &x) ;
l = std::min (l , x) ;
r = std::max (r , x) ;
}
if (l == ) {
printf ("%I64d\n" , calc1 (n - r)) ;
}
else if (r == n) {
printf ("%I64d\n" , calc1 (l - )) ;
}
else printf ("%I64d\n" , calc2 (l - , n - r)) ;
}
return ;
}

hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)的更多相关文章

  1. HDU 5203 Rikka with wood sticks 分类讨论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203 bc(chinese):http://bestcoder.hdu.edu.cn/con ...

  2. 【HDOJ】5203 Rikka with wood sticks

    /* 1002 */ #include <iostream> #include <string> #include <map> #include <queue ...

  3. Rikka with wood sticks(hdu5203)

    Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)

    Problem Description   You live in a village but work in another village. You decided to follow the s ...

  5. HDU 5675 ztr loves math (数学推导)

    ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...

  6. HDU 5680 zxa and set (数学 推导结论)

    zxa and set 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/G Description zxa has a set , ...

  7. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  8. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

  9. HDU 5831 Rikka with Parenthesis II(六花与括号II)

    31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

随机推荐

  1. (转)shell实例手册

    原文地址:http://hi.baidu.com/quanzhou722/item/f4a4f3c9eb37f02d46d5c0d9 实在是太好的资料了,不得不转 shell实例手册 0说明{ 手册制 ...

  2. WampServer下使用多端口访问

    因为学习中要用到跨域请求,所以不得不在wamp集成环境下添加多站点服务. 1.首先你要确保已经正确安装了wamp. 2.接着在wamp的安装目录下找到Apache2的httpd.conf文件,比如我的 ...

  3. Yii2-Redis使用小记 - Cache

    前些天简单学习了下 Redis,现在准备在项目上使用它了.我们目前用的是 Yii2 框架,在官网搜索了下 Redis,就发现了yii2-redis这扩展. 安装后使用超简单,打开 common/con ...

  4. 云计算之路-阿里云上:2014年6月12日14:40出现CPU 100%

    这是今天遇到的第2次故障,主站1台云服务器在14:40:33-14:41:09期间出现CPU突然跑满的状况,而CPU跑满之前,请求量并没有明显增长. 向阿里云提交之后,说晚上会对这台云服务器的虚拟机进 ...

  5. JavaScript基础---语言基础(3)

    流程控制语句 学习要点: 1.switch语句 2.for...in语句 3.break和continue语句 4.with语句 ECMA-262规定了一组流程控制语句.语句定义了ECMAScript ...

  6. Error: java.lang.UnsatisfiedLinkError: no ntvinv in java.library.path

    Error Message When compiling or executing a Java application that uses the ArcObjects Java API, the ...

  7. photoshop将psd导出div+css格式HTML(自动)

    psd切片切好后,导出 web格式,存储时选择html.所有切片,然后,选择其他,选择自定,选择切片,选择生成css css命名有2种方式,根据ID和根据类,一般选择根据类(ID尽量少有,防止js要用 ...

  8. iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式

    一.启动图片设置了没有效果 解决方案:缓存啊!卸了程序重新安装吧!!!!! 二.单独创建xib需要注意的事项 三.图片取消系统渲染的快捷方式

  9. 关于Jquery 操作Cookie 取值错误

    使用JQuery操作cookie时 发生取的值不正确的问题: 结果发现cookie有四个不同的属性: 名称,内容,域,路径 $.cookie('the_cookie'); // 读取 cookie $ ...

  10. Struts2(二)---将页面表单中的数据提交给Action

    问题:在struts2框架下,如何将表单数据传递给业务控制器Action. struts2中,表单想Action传递参数的方式有两种,并且这两种传参方式都是struts2默认实现的,他们分别是基本属性 ...