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 #include <stdio.h>
2 #include<math.h>
3 #include<string.h>
4 #include<math.h>
5 typedef long long LL;
6 const long long mod = 1e9+7;
7 bool check(int a,int b,int c);
8 int main(void)
9 {
10 int n,m;
11 while(scanf("%d %d",&n,&m)!=EOF)
12 {
13 int i,j;
14 int maxx = 0;
15 int minn = 1e9;
16 while(m--)
17 {
18 int id;
19 scanf("%d",&id);
20 if(id > maxx )
21 maxx = id;
22 if(minn > id)
23 {
24 minn = id;
25 }
26 }
27 int ll = minn - 1;
28 int rr = n - maxx;
29 LL sum = 0;
30 if(ll!=0&&rr!=0)
31 {
32 for(i = 1; i <= rr; i++)
33 {
34 int a = ll;
35 int b = i;
36 int c = rr-i;
37 if(check(a,b,c))
38 {
39 sum++;
40 }
41 }
42 for(i = 1; i <= ll; i++)
43 {
44 int a = rr;
45 int b = i;
46 int c = ll-i;
47 if(check(a,b,c))
48 {
49 sum++;
50 }
51 }
52 }
53 else if(ll == 0)
54 {
55 for(i = 1; i <= ((rr-1)/2); i++)
56 {
57 if(rr/2+1-i <= (rr-1)/2)
58 {
59 int yy = (rr-1)/2-rr/2+i;
60 sum += (LL)(yy);
61 }
62 }
63 }
64 else if(rr == 0)
65 {
66 for(i = 1; i <= ((ll-1)/2); i++)
67 { if(ll/2+1-i<=(ll-1)/2)
68 {
69 int yy = (ll-1)/2-ll/2+i;
70 sum+=(LL)(yy);
71 }
72 }
73 }
74 printf("%lld\n",sum);
75 }
76 return 0;
77 }
78 bool check(int a,int b,int c)
79 {
80 if(a+b>c&&b+c>a&&a+c>b)
81 {
82 return true;
83 }
84 return false;
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. Linux三剑客之老三grep

    说明: Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.工作中我们常常用它来过滤出我们想要的数据. 格式: grep [OPTIONS] 基本参 ...

  2. 作为Java技术面试官,我如何深挖候选人的技能

    作为Java资深技术面试官,首先我感觉有必要讲解"面试官深挖问题"的动机,在了解动机的前提下,大家才能更好地准备面试.面试官为什么要在一个点上深挖?两大目的.   1 首先是通过深 ...

  3. InnoDB学习(一)之BufferPool

    我们知道InnoDB数据库的数据是持久化在磁盘上的,而磁盘的IO速度很慢,如果每次数据库访问都直接访问磁盘,显然严重影响数据库的性能.为了提升数据库的访问性能,InnoDB为数据库的数据增加了内存缓存 ...

  4. C语言中的字节对齐

    下面这个篇博客讲解很好 http://blog.csdn.net/meegomeego/article/details/9393783 总的来看分三类: 1. 不加 #pragma pack(n)伪指 ...

  5. HDFS02 HDFS的Shell操作

    HDFS的Shell操作(开发重点) 目录 HDFS的Shell操作(开发重点) 基本语法 常用命令 准备工作 上传 -moveFromLocal 剪切 -copyFromLocal 拷贝 -put ...

  6. spring boot集成mybatis框架

    概述 中文官网:http://www.mybatis.cn 参考教程:https://www.w3cschool.cn/mybatis MyBatis Plus:http://mp.baomidou. ...

  7. BlockingQueue的基本原理

    1. 前言 BlockingQueue即阻塞队列,它算是一种将ReentrantLock用得非常精彩的一种表现,依据它的基本原理,我们可以实现Web中的长连接聊天功能,当然其最常用的还是用于实现生产者 ...

  8. Appium获取toast消息(二)

    刚接触appium进行移动端设备的UI自动化,在遇到toast消息的时候很是苦恼了一阵,最后通过强大的搜索引擎找到了个相对解决方法,废话不多说,直接贴代码↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ...

  9. 如何利用EL表达式获取list,map,对象等值

    <%@ page import="com.hopetesting.domain.User" %><%@ page import="java.util.* ...

  10. 1.ElasticSearch相关概念

    1.为ElasticSearch设置跨域访问 http.cors.enabled: truehttp.cors.allow-origin: "*" 2.什么是ElasticSear ...