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 ...
随机推荐
- 文件和目录之间建立链接 (ln)
- E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing
解决办法:apt-get update或者apt-get cleanapt-get update 或者 apt-get update --fix-missing问题解析1 source本身的问题 根据 ...
- 大数据学习day29-----spark09-------1. 练习: 统计店铺按月份的销售额和累计到该月的总销售额(SQL, DSL,RDD) 2. 分组topN的实现(row_number(), rank(), dense_rank()方法的区别)3. spark自定义函数-UDF
1. 练习 数据: (1)需求1:统计有过连续3天以上销售的店铺有哪些,并且计算出连续三天以上的销售额 第一步:将每天的金额求和(同一天可能会有多个订单) SELECT sid,dt,SUM(mone ...
- ABA 问题
CAS 导致 ABA 问题CAS 算法实现了一个重要的前提,需要取出内存中某时刻的数据,并在当下时刻比较并替换,那么这个时间差会导致数据的变化. 比如说一个线程 one 从内存位置 V 中取出A,这时 ...
- 【Linux】【Basis】块存储,文件存储,对象存储
1. 块存储: 定义:这种接口通常以QEMU Driver或者Kernel Module的方式存在,这种接口需要实现Linux的Block Device的接口或者QEMU提供的Block Driver ...
- Local Classes in C++
A class declared inside a function becomes local to that function and is called Local Class in C++. ...
- 记一次ssh连接慢
2020-03-28日机房搬迁完后,发现有一台60服务器ssh连接特别慢,但是其他服务器正常; 下面是解决过程: vim /etc/ssh/sshd_config (编辑配置文件) 查找F ...
- 学习笔记--html篇(1)
html学习--1 href学习 href="javascript:void(0)" 阻止页面跳转类似于javascript:#,url无变化(死链接,返回undefined) h ...
- 转:Android控件属性
Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料,花费本人一个下午搞出来的,希望对其他人有用. 第一类:属性值为true或false android: ...
- 【论文笔记】SamWalker: Social Recommendation with Informative Sampling Strategy
SamWalker: Social Recommendation with Informative Sampling Strategy Authors: Jiawei Chen, Can Wang, ...