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. WPF MVVM实现TreeView

    今天有点时间,做个小例子WPF MVVM 实现TreeView 只是一个思路大家可以自由扩展 文章最后给出了源码下载地址 图1   图2     模版加上了一个checkbox,选中父类的checkb ...

  2. java8特性深入解读文章合集

    Java 8新特性列表 官方OpenJDK java8核心类库新特性列表 Lambda表达式 java8 lambda表达式被誉为java语言10年来最大的突破,给用户提供了scala和clojure ...

  3. php 验证格式的函数总结

    在首页上看到了这篇总结性的文章,就收藏了起来,想转载过来留着以后方便查看,但是没有找到转载的地,就只有copy下来了.在这里谢谢群主的分享! // ※CheckMoney($C_Money) 检查数据 ...

  4. android常用的弹出提示框

    我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其他平台开发经验的朋友都会知道,大部分的平台都只提供了几个最简单的实现,如果我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承等 ...

  5. jQuery 选择器语法

    jQuery选择器分为如下几类(点击“名称”会跳转到此方法的jQuery官方说明文档): 1. 基础选择器 Basics 名称 说明 举例 #id 根据元素Id选择 $("divId&quo ...

  6. iOS边练边学--菜单悬停效果的实现思路

  7. text-align:justify_内容居中对齐

    一直发现text-align : justify这个对齐方式不好使,都不知道为什么么么哒: 因为两端对齐的这个行的结束要一个有空字符串或者别的不可见的字符,用户代理会把这个行的最后几个字符往右边拉,实 ...

  8. css中的默认margin

    上班打酱油中,你懂的; body的margin为8px; webkit默认行高18px:height18px; 默认font-size16px p默认margin是16px 0 16px 0; ul和 ...

  9. poppin_xpower_ 常城

  10. BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...