Rikka with wood sticks

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

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
思路:那段不好的肯定要包括全部的坏木。
所以有三种情况坏的那段[minn,maxx];minn>1&&maxx<n;
那么定一段,然后暴力枚举另一段分成两段;
minn==1,那么就是[maxx+1,n]要分成三段的方案,那么这个就是a+b+c=l;
那么c = l-a-b;那么根据三角形三边限制就可以得到方程组a+b > l/2;
a < l/2;b<l/2;
那么暴力枚举a统计b就行了;
maxx == n这个和第二中是一样的
复杂度O(n);
  1. 1 #include <stdio.h>
  2. 2 #include<math.h>
  3. 3 #include<string.h>
  4. 4 #include<math.h>
  5. 5 typedef long long LL;
  6. 6 const long long mod = 1e9+7;
  7. 7 bool check(int a,int b,int c);
  8. 8 int main(void)
  9. 9 {
  10. 10 int n,m;
  11. 11 while(scanf("%d %d",&n,&m)!=EOF)
  12. 12 {
  13. 13 int i,j;
  14. 14 int maxx = 0;
  15. 15 int minn = 1e9;
  16. 16 while(m--)
  17. 17 {
  18. 18 int id;
  19. 19 scanf("%d",&id);
  20. 20 if(id > maxx )
  21. 21 maxx = id;
  22. 22 if(minn > id)
  23. 23 {
  24. 24 minn = id;
  25. 25 }
  26. 26 }
  27. 27 int ll = minn - 1;
  28. 28 int rr = n - maxx;
  29. 29 LL sum = 0;
  30. 30 if(ll!=0&&rr!=0)
  31. 31 {
  32. 32 for(i = 1; i <= rr; i++)
  33. 33 {
  34. 34 int a = ll;
  35. 35 int b = i;
  36. 36 int c = rr-i;
  37. 37 if(check(a,b,c))
  38. 38 {
  39. 39 sum++;
  40. 40 }
  41. 41 }
  42. 42 for(i = 1; i <= ll; i++)
  43. 43 {
  44. 44 int a = rr;
  45. 45 int b = i;
  46. 46 int c = ll-i;
  47. 47 if(check(a,b,c))
  48. 48 {
  49. 49 sum++;
  50. 50 }
  51. 51 }
  52. 52 }
  53. 53 else if(ll == 0)
  54. 54 {
  55. 55 for(i = 1; i <= ((rr-1)/2); i++)
  56. 56 {
  57. 57 if(rr/2+1-i <= (rr-1)/2)
  58. 58 {
  59. 59 int yy = (rr-1)/2-rr/2+i;
  60. 60 sum += (LL)(yy);
  61. 61 }
  62. 62 }
  63. 63 }
  64. 64 else if(rr == 0)
  65. 65 {
  66. 66 for(i = 1; i <= ((ll-1)/2); i++)
  67. 67 { if(ll/2+1-i<=(ll-1)/2)
  68. 68 {
  69. 69 int yy = (ll-1)/2-ll/2+i;
  70. 70 sum+=(LL)(yy);
  71. 71 }
  72. 72 }
  73. 73 }
  74. 74 printf("%lld\n",sum);
  75. 75 }
  76. 76 return 0;
  77. 77 }
  78. 78 bool check(int a,int b,int c)
  79. 79 {
  80. 80 if(a+b>c&&b+c>a&&a+c>b)
  81. 81 {
  82. 82 return true;
  83. 83 }
  84. 84 return false;
  85. 85 }

Rikka with wood sticks(hdu5203)的更多相关文章

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

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

  2. 【HDOJ】5203 Rikka with wood sticks

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

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

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

  4. HDOJ-1051 Wooden sticks(贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. Little Zu Chongzhi's Triangles

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  6. HDU5135 dfs搜索 枚举种数

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  7. HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  8. hdu5135 Little Zu Chongzhi's Triangles

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...

  9. 10003 Cutting Sticks(区间dp)

      Cutting Sticks  You have to cut a wood stick into pieces. The most affordable company, The Analog ...

随机推荐

  1. 文件和目录之间建立链接 (ln)

  2. E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing

    解决办法:apt-get update或者apt-get cleanapt-get update 或者 apt-get update --fix-missing问题解析1 source本身的问题 根据 ...

  3. 大数据学习day29-----spark09-------1. 练习: 统计店铺按月份的销售额和累计到该月的总销售额(SQL, DSL,RDD) 2. 分组topN的实现(row_number(), rank(), dense_rank()方法的区别)3. spark自定义函数-UDF

    1. 练习 数据: (1)需求1:统计有过连续3天以上销售的店铺有哪些,并且计算出连续三天以上的销售额 第一步:将每天的金额求和(同一天可能会有多个订单) SELECT sid,dt,SUM(mone ...

  4. ABA 问题

    CAS 导致 ABA 问题CAS 算法实现了一个重要的前提,需要取出内存中某时刻的数据,并在当下时刻比较并替换,那么这个时间差会导致数据的变化. 比如说一个线程 one 从内存位置 V 中取出A,这时 ...

  5. 【Linux】【Basis】块存储,文件存储,对象存储

    1. 块存储: 定义:这种接口通常以QEMU Driver或者Kernel Module的方式存在,这种接口需要实现Linux的Block Device的接口或者QEMU提供的Block Driver ...

  6. Local Classes in C++

    A class declared inside a function becomes local to that function and is called Local Class in C++. ...

  7. 记一次ssh连接慢

    2020-03-28日机房搬迁完后,发现有一台60服务器ssh连接特别慢,但是其他服务器正常; 下面是解决过程: vim /etc/ssh/sshd_config       (编辑配置文件) 查找F ...

  8. 学习笔记--html篇(1)

    html学习--1 href学习 href="javascript:void(0)" 阻止页面跳转类似于javascript:#,url无变化(死链接,返回undefined) h ...

  9. 转:Android控件属性

    Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料,花费本人一个下午搞出来的,希望对其他人有用. 第一类:属性值为true或false android: ...

  10. 【论文笔记】SamWalker: Social Recommendation with Informative Sampling Strategy

    SamWalker: Social Recommendation with Informative Sampling Strategy Authors: Jiawei Chen, Can Wang, ...