Rikka with wood sticks(hdu5203)
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
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?
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)的更多相关文章
- 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 ...
- 【HDOJ】5203 Rikka with wood sticks
/* 1002 */ #include <iostream> #include <string> #include <map> #include <queue ...
- HDU 5203 Rikka with wood sticks 分类讨论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203 bc(chinese):http://bestcoder.hdu.edu.cn/con ...
- HDOJ-1051 Wooden sticks(贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Little Zu Chongzhi's Triangles
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- HDU5135 dfs搜索 枚举种数
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- 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 ...
- hdu5135 Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...
- 10003 Cutting Sticks(区间dp)
Cutting Sticks You have to cut a wood stick into pieces. The most affordable company, The Analog ...
随机推荐
- 【模板】Splay(伸展树)普通平衡树(数据加强版)/洛谷P6136
题目链接 https://www.luogu.com.cn/problem/P6136 题目大意 需要写一种数据结构,来维护一些非负整数( \(int\) 范围内)的升序序列,其中需要提供以下操作: ...
- 听老外吐槽框架设计,Why I Hate Frameworks?
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. Hello,小伙伴们,今天不聊技术,分享点有意思的东西.前段时间,表弟给我发过来一篇老外写的文章,以略带讽刺的对话方式调侃了自己对框架的看法,我 ...
- 云原生PaaS平台通过插件整合SkyWalking,实现APM即插即用
一. 简介 SkyWalking 是一个开源可观察性平台,用于收集.分析.聚合和可视化来自服务和云原生基础设施的数据.支持分布式追踪.性能指标分析.应用和服务依赖分析等:它是一种现代 APM,专为云原 ...
- C语言中的字节对齐
下面这个篇博客讲解很好 http://blog.csdn.net/meegomeego/article/details/9393783 总的来看分三类: 1. 不加 #pragma pack(n)伪指 ...
- k8s使用ceph的rbd作后端存储
k8s使用rbd作后端存储 k8s里的存储方式主要有三种.分别是volume.persistent volumes和dynamic volume provisioning. volume: 就是直接挂 ...
- adb命令对app进行测试
1.何为adb adb android debug bridge ,sdk包中的工具,将Platform-tooks 和tools 两个路径配置到环境变量中 2.SDK下载链接:http://t ...
- Hibernate持久化标志符生成策略
generator子元素定义持久化标识符的生成策略,为持久化类对应的数据库表的主键找到了赋值方法,HIbernate默认将使用assigned的持久化标识符生成策略.关系型数据库的主键定义方式:(1) ...
- SpringMVC原理分析
Spring MVC主要包括以下要点: 1:由DispatcherServlet控制的整个流程: 2:注解驱动的控制器,其中包括请求映射.数据的绑定和格式化: 3:文件上传: 4:一些杂项,如静态资源 ...
- Can a C++ class have an object of self type?
A class declaration can contain static object of self type,it can also have pointer to self type,but ...
- nodejs代码初探之nodejs启动
nodejs启动 入口在node_main.cc,解析参数后进入node.cc 中的node::Start() V8::Initialize() //初始化v8SetupProcessObject() ...