1.3.2 Barn Repair【贪心】
来源:互联网 发布:武汉 人工智能 编辑:程序博客网 时间:2024/06/05 17:28
链接
/*ID: email_f1LANG: C++PROG: barn1*/#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <set>#include <map>#include <stack>#include <queue>#include <vector>#include <iostream>#include <algorithm>using namespace std;#define ll long long#define eps 10^(-6)#define Q_CIN ios::sync_with_stdio(false);#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define CLR( a , x ) memset ( a , x , sizeof (a) );#define RE freopen("barn1.in","r",stdin);#define WE freopen("barn1.out","w",stdout);#define MOD 10009#define bug(x) cout<<#x<<":"<<(x)<<endl;//用最短的长度将区间覆盖,则给的木板数当然都用上最省了,也就是说用M根板尽量短地覆盖//首先假设用板将全部有牛的覆盖掉,然后每次挑里面最大的空隙,在那里切开(覆盖到没牛的棚当然要尽量少),直到木板没了。//如果木板数大于有牛的数,则长度为牛数//空隙:6-5=1但没有空隙,7-5才有int a[250],len[250];bool cmp(int a,int b){ return a>b;}int main(){ RE WE int m,s,c; while(cin>>m>>s>>c) { REP(i,c) cin>>a[i]; int ans; if(m>=c) //如果木板足够,则有多少个带牛的牛棚就多少长度 ans=c; else { sort(a,a+c); //编号不一定升序 FOR(i,1,c) len[i]=a[i]-a[i-1]-1; len[0]=0; ans=a[c-1]-a[0]+1; //最后个有牛-第一个有牛 sort(len,len+c,cmp); //长度降序排序 int tmp=0,idx=0; //idx=0 m--; //先给全部搭成一块,剩余块数-1 while(m--) //每切一刀多一块,则剩余的块数减少1 { ans-=len[idx]; idx++; } } cout<<ans<<endl; } return 0;}
0 0
- 1.3.2 Barn Repair【贪心】
- usaco-1.3.2-Barn Repair(贪心算法)
- USACO 1.3 - Barn Repair(贪心)
- 1.3.2 Barn Repair
- 1.3.2 Barn Repair
- 1.3.2---Barn Repair
- 【USACO-Chapter1-1.3】【贪心】Barn Repair
- usaco 1.3 Barn Repair(贪心)
- USACO 1.3 Barn Repair(贪心)
- USACO-Section 1.3 Barn Repair(贪心)
- USACO 1.3 Barn Repair (快排+贪心)
- USACO/Barn Repair(贪心)
- USACO Barn Repair----贪心
- [USACO 1.3.2] Barn Repair
- USACO 1.3.2 Barn Repair
- USACO 1.3.2 Barn Repair
- usaco 1.3.2 Barn Repair
- USACO 1.3.2 Barn Repair
- HDU 1166 敌兵布阵(线段树)
- 在html 中,将中文转换为 html实体再输出 即: &#开头的html实体编码
- 一个完整的schema验证xml的例子
- 如何在DataTable中查找数据
- hd-1096:A+B for Input-Output Practice (VIII)
- 1.3.2 Barn Repair【贪心】
- 关于java基础--PIO操作xls文件、持久化对象以及拷贝文件
- NYOJ 1112 求次数(map)
- Solr常见问题记录
- 循环队列相关知识
- 1610 - Party Games(细节题)
- alert的用法
- poj 3321/3263 树状数组(苹果树/排身高)
- [转载]怎么写出一本程序员风格的修真小说?