博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)...
阅读量:5260 次
发布时间:2019-06-14

本文共 2723 字,大约阅读时间需要 9 分钟。

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 n1 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(1n1000000,1m1000). 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

 

1 #include
2 #include
3 typedef __int64 ll ; 4 int n , m ; 5 int l , r ; 6 7 bool ok (int a , int b , int c) 8 { 9 if (a + b > c && a + c > b && b + c > a)10 return true ;11 return false ;12 }13 14 ll calc2 (int lg , int wd)15 {16 if (lg == wd) return 0 ;17 if (lg < wd) std::swap (lg , wd) ;18 int x = (lg - wd)/2 ;19 if (x == 0) x ++ ;20 if (ok (x , lg - x , wd))21 return lg - 1 - (x - 1) * 2 ;22 else23 return lg - 1 - x * 2 ;24 }25 26 ll calc1 (int lg)27 {28 ll tot = 0 ;29 for (int i = 1 ; i <= lg/2 ; i++) {30 tot += calc2 (i , lg - i) ;31 }32 return tot ;33 }34 35 int main ()36 {37 //freopen ("a.txt" , "r" , stdin ) ;38 while (~ scanf ("%d%d" , &n, &m)) {39 l = n , r = 1 ;40 for (int i = 0 ; i < m ; i++) {41 int x ;42 scanf ("%d" , &x) ;43 l = std::min (l , x) ;44 r = std::max (r , x) ;45 }46 if (l == 1) {47 printf ("%I64d\n" , calc1 (n - r)) ;48 }49 else if (r == n) {50 printf ("%I64d\n" , calc1 (l - 1)) ;51 }52 else printf ("%I64d\n" , calc2 (l - 1 , n - r)) ;53 }54 return 0 ;55 }
View Code

 

转载于:https://www.cnblogs.com/get-an-AC-everyday/p/4425954.html

你可能感兴趣的文章
MySQL导入数据报 Got a packet bigger than‘max_allowed_packet’bytes 错误的解决方法
查看>>
jquery中“this”不同时刻的不同含义
查看>>
hdu 1686 & poj 2406 & poj 2752 (KMP入门三弹连发)
查看>>
iOS的多版本配置(版本分离,多环境配置)
查看>>
Java中定时器相关实现的介绍与对比之:ScheduledExecutor
查看>>
【URAL】1297 Palindrome
查看>>
Android学习笔记:如何设置ImageView中图片的显示方式
查看>>
三次握手
查看>>
Scale和Resolution的含义及转换算法
查看>>
according
查看>>
配置tomcat的开发环境
查看>>
实现可串行化类的步骤
查看>>
mac安装OpenCV
查看>>
二分查找算法
查看>>
Bootstrap响应式导航
查看>>
21天战拖记——Day20:整理自己的桌面(2014-05-23)
查看>>
Linux curl命令中,HTTP 302处理
查看>>
WS103C8例程——串口2【worldsing笔记】
查看>>
[poj2762] Going from u to v or from v to u?(Kosaraju缩点+拓排)
查看>>
Git与Github的连接与使用
查看>>