# USACO Barn Repair 题解

```/*
ID: bbsunch2
PROG: barn1
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main()
{
ofstream fout ("barn1.out");
ifstream fin ("barn1.in");

int boardNum = 0;
int stallNum = 0;
int cowStall = 0;
fin >> boardNum >> stallNum >> cowStall;
//cout << boardNum << stallNum << cowStall << endl;
vector <int> stall;
vector<int> gap;
for(int i = 0; i < cowStall; i++)
{
int s;
fin >> s;
stall.push_back(s);
}
sort(stall.begin(), stall.end());
int former = 0;
former = stall[0];
for(int i = 1; i < stall.size(); i++)
{
int latter = stall[i];

if(latter - former > 1)
{
//cout << former << " " << latter << endl;
gap.push_back(latter - former - 1);
}
former = latter;
}
//cout << gap.size() << endl;
//for(int i = 0; i < gap.size(); i++)
//{
//    cout << gap[i] << endl;
//}
sort(gap.begin(), gap.end());
//cout << "test" << endl;
//cout << gap.size() << endl;

int gapNum = boardNum - 1;

if(gapNum > gap.size())
{
gapNum = gap.size();
}
for(int i = 0; i < gapNum; i++)
{
gap.erase(gap.end()-1);
}

for(int i = 0; i < gap.size(); i++)
{
cowStall += gap[i];
}
fout << cowStall << endl;
return 0;
}
```

USACO Barn Repair 题解

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊

POJ 3168 Barn Expansion扩地：有N块不重叠的矩形地，由左下角（A,B）和右上角（C,D）决定。如果两
【问题描述】 据说如果你给无限只母牛和无限台巨型便携式电脑(有非常大的键盘),那么母牛们会制造出

#include <cstdio> #include <iostream> #include <algorithm> using namespace

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a
【描述】 给定4个矩形块，找出一个最小的封闭矩形将这4个矩形块放入，但不得相互重叠。所谓最小矩形