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. 20145222黄亚奇《Java程序设计》第9周学习总结

    20145222第九周<Java学习笔记>学习总结 教材学习内容总结 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找 JDBC(Ja ...

  2. try-catch和throw,throws的区别和联系

    转载:http://blog.sina.com.cn/s/blog_62148d1e0100hkqc.html 区别一:throw 是语句抛出一个异常:throws 是方法抛出一个异常: throw语 ...

  3. flatbuffers 使用问题记录

    1. 命名空间的问题 ----------------------------- namespace 1.0.3 版本包含文件类型前面不需要加命名空间,但是1.1.0 中包含需要在类型前加命名空间 i ...

  4. 使用DOM动态创建标签

    本文是参考<javascript Dom 编程艺术>第八章的内容所写,用到的知识点,就是关于创建平稳的web页面. 使用DOM方法: getElementById() getElement ...

  5. 每天一个linux命令(26):du 命令

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...

  6. 【转载】Velocity模板引擎的介绍和基本的模板语言语法使用

    原文地址http://www.itzhai.com/the-introduction-of-the-velocity-template-engine-template-language-syntax- ...

  7. ADHelper C#域用户操作(转)

    using System; using System.Collections.Generic; using System.DirectoryServices; using System.Linq; u ...

  8. codevs1227 方格取数2 注意数组啊啊啊啊啊啊啊啊啊啊

    一开始T了一组RE了一组,实在找不出错来,就把数组加了一个0竟然就多A了一组.很惊讶的又加了几个0最后竟然全A了!!! 懒得做了,改的是之前的那个蚯蚓的游戏问题.还是需要拆点,至于为什么不能重复走结点 ...

  9. uva12532 线段树单点更新

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  10. Ajax 的缺点

    1.ajax干掉了back按钮,即对浏览器后退机制的破坏.后退按钮是一个标准的web站点的重要功能,但是它没法和js进行很好的合作.这是ajax所带来的一个比较严重的问题,因为用户往往是希望能够通过后 ...