barn1
来源:互联网 发布:淘宝怎么修改差评? 编辑:程序博客网 时间:2024/06/05 14:42
Barn Repair
简述:
给一定量的木板m,拿木板去挡住最多s间房子,其实只有c间房子里住(也就是说,把给了编号的这c间房子遮住就好了)。所以,需要遮住的房子最少有多少呢。
重点就在于木板定量,所以有的空房子也要用连着的木板遮起来。我的想法是,先把空的房间按照段分开计数,然后找出m - 1段最长的空房子,从这里断开,这样连起来的房子肯定是最省材料的。不过呢,万一木材的数量很多呢,那就只需要把所有的空段都减掉,就好了。
代码:
#include <stdio.h>#include <stdlib.h>int a[250],b[250];int cmp(const void *a, const void *b){ return *(int *)b - *(int *)a;}int main(void){ freopen("barn1.in", "r", stdin); freopen("barn1.out", "w", stdout); int i, m, s, c, t, cb = 0, cnt = 0, mn, mx, len; scanf("%d %d %d", &m, &s, &c); for(i = 1; i < c + 1; i++) { scanf("%d", &t); if(i == 1)mx = mn = t; if(mx < t)mx = t; if(mn > t)mn = t; a[t] = 1; } len = mx - mn + 1; for(i = mn; i < mx + 1; i++) { if(a[i] == 1) { if(cnt > 0)b[cb++] = cnt; cnt = 0; } else cnt++; } m = m > cb ? cb : m - 1; qsort(b, cb, sizeof(int), cmp); for(i = 0; i < m; i++) len -= b[i]; printf("%d\n", len); return 0;}
阅读全文
0 0
- barn1
- USACO barn1
- 1.3 barn1
- 【USACO】barn1
- usaco barn1
- usaco——barn1
- USACO 1.3 barn1
- usaco/ 1.3 milk/barn1
- usaco 1.3.2 barn1
- USACO 1.3 barn1
- barn1<uscao>1.3 -<贪心>
- barn1-section1.3
- S 1.3 barn1 C语言
- USACO 1.3 Barn Repair (barn1)
- USACO1.3.2 Barn Repair (barn1)
- USACO1.3.2 Barn Repair (barn1)
- USACO-Section1.3 barn1[贪心]
- USACO 1.3.2 Barn Repair (barn1)
- Linux下软件安装的几种方式
- js预编译
- 基础练习 龟兔赛跑预测
- yii框架对独立操作的写法与使用
- Ubuntu16.04 双卡+cuda8.0安装
- barn1
- Redis之运维细节
- 实现haproxy+LNMT负载均衡架构
- hdu--进制转换
- 【TensorFlow】Windows10 64位下安装TensorFlow
- PAT
- Python3之爬虫selenium+chromedriver资源下载及“Message: 'chromedriver' executable needs to be in PATH.处理
- <c:forEach>的用法
- 关于Android L的Service启动问题