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 ...
随机推荐
- (转载)VB中ByVal与ByRef的区别
ByVal是按值传送,在传的过程中不会改变原来的值,仅仅传送的是一个副本, 而 ByRef相反,从内存地址来说,后者是同一个内存地址. ByVal 与 ByRef(默认值)这两个是子过程的参数传递时, ...
- 学习java 7.13
学习内容: 一个汉字存储:如果是GBK编码,占用2个字节:如果是UTF-8编码,占用3个字节 汉字在存储的时候,无论选择哪种编码存储,第一个字节都是负数 字符流=字节流+编码表 采用何种规则编码,就要 ...
- 零基础学习java------day18------properties集合,多线程(线程和进程,多线程的实现,线程中的方法,线程的声明周期,线程安全问题,wait/notify.notifyAll,死锁,线程池),
1.Properties集合 1.1 概述: Properties类表示了一个持久的属性集.Properties可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串 一个属性列表可包含另 ...
- centos 7 重新获取IP地址
1.安装软件包 dhclient # yum install dhclient 2.释放现有IP # dhclient -r 3.重新获取 # dhclient 4.查看获取到到IP # ip a
- Linux基础命令---mysqlshow显示数据库
mysqlshow mysqlshow是一个客户端的程序,它可以显示数据库的信息.表信息.字段信息. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora. 1.语法 ...
- Synchronized深度解析
概览: 简介:作用.地位.不控制并发的影响 用法:对象锁和类锁 多线程访问同步方法的7种情况 性质:可重入.不可中断 原理:加解锁原理.可重入原理.可见性原理 缺陷:效率低.不够灵活.无法预判是否成功 ...
- 【简】题解 P4297 [NOI2006]网络收费
传送门:P4297 [NOI2006]网络收费 题目大意: 给定一棵满二叉树,每个叶节点有一个状态(0,1),任选两个叶节点,如果这两个叶节点状态相同但他们的LCA所管辖的子树中的与他们状态相同的叶节 ...
- YC-Framework版本更新:V1.0.2
分布式微服务框架:YC-Framework版本更新V1.0.2!!! 版本更新,本次版本为V1.0.2 主要更新内容如下所示: 集成ActiveMQ; 集成微信生态(支持微信公众号.微信支付.微信开放 ...
- 【Fastjson】Fastjson反序列化由浅入深
Fastjson真-简-介 fastjson是由alibaba开发并维护的一个json工具,以其特有的算法,号称最快的json库 fastjson的使用 首先先创一个简单的测试类User public ...
- 【kafka学习笔记】合理安排broker、partition、consumer数量
broker的数量最好大于等于partition数量 一个partition最好对应一个硬盘,这样能最大限度发挥顺序写的优势. broker如果免得是多个partition,需要随机分发,顺序IO会退 ...