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. X-MagicBox-820的luatOS之路连载系列6

    继上次用Qt实现了显示地图和MQTT通信之后(X-MagicBox-820的luatOS之路连载系列5),说是要研究下地图的开放接口,也看了标记点和线的方法(地图上自定义标记点和轨迹线的实现).这次就 ...

  2. 学习java的第二十二天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...

  3. JS控制元素的显示和隐藏

    利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: document.getElementB ...

  4. ssh : connect to host XXX.XXX.XXX.XXX port : 22 connect refused

    初学者 写博客 如有不对之处请多多指教 我是要在俩个主机的俩个虚拟机上 用scp (security copy)进行文件远程复制. 但是 终端 提示 ssh : connect to host XXX ...

  5. 【分布式】Zookeeper客户端基本的使用

    与mysql.redis等软件一样,zookeeper的软件包中也提供了客户端程序用于对服务器上的数据进行操作.本节我们就来学习zookeeper客户端的使用方法.不过在详细讲解zk客户端的使用方法之 ...

  6. How is Quality Score Calculated?

    Google determines Quality Score slightly differently for each of the different advertising networks ...

  7. [项目总结]关于调用系统照相机Activity被销毁问题解决

    在项目中需要启用系统照相机来拍照.本来很容易的一个问题.但在适配中出现了问题. 简单说一下问题: 有些手机拍照成功,有些手机拍完照后确定返回后activity数据丢失,被销毁了. 问题查找: 经过代码 ...

  8. 【Python】【Algorithm】排序

    冒泡排序 dic = [12, 45, 22, 6551, 74, 155, 6522, 1, 386, 15, 369, 15, 128, 123, ] for j in range(1, len( ...

  9. python pandas 中文件的读写——read_csv()读取文件

    read_csv()读取文件1.python读取文件的几种方式read_csv 从文件,url,文件型对象中加载带分隔符的数据.默认分隔符为逗号read_table 从文件,url,文件型对象中加载带 ...

  10. maven依赖对zookeeper的版本冲突问题

    我用的是springcloudAlibaba+zookeeper zookeeper下载后 1,修改配置文件,conf目录下的zoo_sample.cfg修改为zoo.cfg. 2,打开zoo.cfg ...