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 ...
随机推荐
- linux下vim的安装与配置(centos)
1.vim的安装 #yum search vim //查看vim相关软件信息 #yum install -y vim* //在线安装vim 2.vim的配置 (1)~/.viminfo 在vim ...
- svn简单上传下载文件命令
上传命令: svn import 本地文件或目录 远程服务端目录 --username '用户名' --password '密码' -m '添加描述(可为空)' 下载命令: svn export 远程 ...
- CMakeLists.txt添加多个源代码
coos2d-x 3.17.2 C++工程,安卓编译使用CMake,按照模板给的写法,只能一个一个源文件添加:如果需要添加大量的C++源代码,这种方式肯定不可取:原来的写法: 1 list(APPEN ...
- 『与善仁』Appium基础 — 19、元素定位工具(三)
目录 1.Chrome Inspect介绍 2.Chrome Inspect打开方式 3.Chrome Inspect工具的使用 (1)Chrome Inspect工作前提 (2)Chrome Ins ...
- 使用 Skywalking 对 Kubernetes(K8s)中的微服务进行监控
1. 概述 老话说的好:任何成功都不是轻易得来的,是不断地坚持与面对的结果. 言归正传,之前我们聊了 SpringCloud 开发的微服务是如何部署在 Kubernetes(K8s)集群中的,今天我 ...
- mysql数据查询语言DQL
DB(database)数据库:存储数据的'仓库',保存了一系列有组织的数据 DBMS(Database Management System)数据库管理系统:用于创建或管理DB SQL(Structu ...
- 深入理解mysql锁与事务隔离级别
一.锁 1.锁的定义 锁即是一种用来协调多线程或进程并发使用同一共享资源的机制 2.锁的分类 从性能上分类:乐观锁和悲观锁 从数据库操作类型上分类:读锁和写锁 从操作粒度上分类:表锁和行锁 2 ...
- day08 索引的创建与慢查询优化
day08 索引的创建与慢查询优化 昨日内容回顾 视图 视图:将SQL语句查询结果实体化保存起来,方便下次查询使用. 视图里面的数据来源于原表,视图只有表结构 # 创建视图 create view 视 ...
- Flink(四)【IDEA执行查看Web UI】
1.导入依赖 <!-- flink Web UI --> <dependency> <groupId>org.apache.flink</groupId> ...
- 【XSS】再谈CSP内容安全策略
再谈CSP内容安全策略 之前每次都是想的很浅,或者只是个理论派,事实证明就是得动手实践 参考 CSP的用法 官方文档 通过设置属性来告诉浏览器允许加载的资源数据来源.可通过Response响应头来设置 ...