Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Aug 7, 2019
1 parent 3bd9799 commit 2b68cc9
Show file tree
Hide file tree
Showing 20 changed files with 1,097 additions and 235 deletions.
Binary file modified doc/Other/RMQ问题.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "simpleMindedHashing_UVA10912"; //*
const string CPPfile = "maps"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
137 changes: 81 additions & 56 deletions myCpps/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ofstream fout("maps.out");

const int inf = INT_MAX / 2;

const int maxP = 400;

class rect
{
public:
Expand All @@ -22,88 +24,111 @@ class line
int x;
int y1;
int y2;
int last;

bool operator<(const line & temp) const
{
return x < temp.x;
}
};
line _line(int x, int y1, int y2, int last)
line _line(int x, int y1, int y2)
{
line temp{x, y1, y2, last}; return temp;
line temp{x, y1, y2}; return temp;
}

int main()
{
int n; fin >> n;
fout << fixed << setprecision(2);

vector<rect> a_t(n);
set<double> _set;
for (int i = 0; i <= n - 1; ++i)
int t = 0;
while (true)
{
fin >> a_t[i].x1 >> a_t[i].y1 >> a_t[i].x2 >> a_t[i].y2;
_set.insert(a_t[i].x1);
_set.insert(a_t[i].y1);
_set.insert(a_t[i].x2);
_set.insert(a_t[i].y2);
}
int n = 0; fin >> n;
if (n == 0) break;

int _i = 0;
vector<double> itod;
map<double, int> dtoi;
for (auto it = _set.begin(); it != _set.end(); ++it)
{
double x = *it;
++t;

itod.push_back(x);
dtoi[x] = _i;
++_i;
}
vector<rect> a_t(n);
set<double> _set;
for (int i = 0; i <= n - 1; ++i)
{
fin >> a_t[i].x1 >> a_t[i].y1 >> a_t[i].x2 >> a_t[i].y2;
_set.insert(a_t[i].x1);
_set.insert(a_t[i].y1);
_set.insert(a_t[i].x2);
_set.insert(a_t[i].y2);
}

vector<rect> a(n);
for (int i = 0; i <= n - 1; ++i)
{
a[i].x1 = dtoi[a_t[i].x1];
a[i].y1 = dtoi[a_t[i].y1];
a[i].x2 = dtoi[a_t[i].x2];
a[i].y2 = dtoi[a_t[i].y2];
}
int _i = 0;
vector<double> itod;
map<double, int> dtoi;
for (auto it = _set.begin(); it != _set.end(); ++it)
{
double x = *it;

vector<line> l;
for (int i = 0; i <= n - 1; ++i)
{
l.push_back(_line(a[i].x1, a[i].y1, a[i].y2, a[i].x2 - a[i].x1));
l.push_back(_line(a[i].x2, a[i].y1, a[i].y2, 0));
}
sort(l.begin(), l.end());
itod.push_back(x);
dtoi[x] = _i;
++_i;
}

int sizeL = l.size();
vector<int> minH(itod.size() + 1, inf), maxH(itod.size() + 1, -1);
for (int i = 0; i <= sizeL - 1; ++i)
{
for (int x = l[i].x; x <= l[i].x + l[i].last; ++x)
vector<rect> a(n);
for (int i = 0; i <= n - 1; ++i)
{
minH[x] = min(minH[x], l[i].y1);
maxH[x] = max(maxH[x], l[i].y2);
a[i].x1 = dtoi[a_t[i].x1];
a[i].y1 = dtoi[a_t[i].y1];
a[i].x2 = dtoi[a_t[i].x2];
a[i].y2 = dtoi[a_t[i].y2];
}
}

double ans = 0, lastH = 0.0, lastX = 0.0;
for (int i = 0; i <= sizeL - 1; ++i)
{
int x = l[i].x;
double nowH = itod[maxH[x]] - itod[minH[x]], nowX = itod[l[i].x];
vector<line> l;
for (int i = 0; i <= n - 1; ++i)
{
l.push_back(_line(a[i].x1, a[i].y1, a[i].y2));
l.push_back(_line(a[i].x2, a[i].y1, a[i].y2));
}
sort(l.begin(), l.end());

if (i > 0)
int sizeL = l.size();
vector<double> h(itod.size() + 1, 0.0);
for (int i = 0; i <= sizeL - 2; ++i)
{
ans += (min(nowH, lastH) * (nowX - lastX));
int nowX = l[i].x, nextX = l[i + 1].x;

if (nowX == nextX) continue;

vector<int> thisH(maxP, 0);
for (int j = 0; j <= n - 1; ++j)
{
if (a[j].x1 <= nowX && nextX <= a[j].x2)
{
for (int y = a[j].y1; y <= a[j].y2 - 1; ++y)
{
thisH[y] = 1;
}
}
}

for (int y = 0; y <= maxP - 1; ++y)
{
if (thisH[y] == 1)
{
h[i] += (itod[y + 1] - itod[y]);
}
}
}

lastH = nowH; lastX = nowX;
}
double ans = 0;
for (int i = 0; i <= sizeL - 2; ++i)
{
int nowX = l[i].x, nextX = l[i + 1].x;

ans += (h[i] * (itod[nextX] - itod[nowX]));
}

fout << ans << '\n';
//ans = (int)(ans * 100.0 + 0.5) / 100.0;

fout << "Test case #" << t << '\n';
fout << "Total explored area: " << ans << '\n';

}
return 0;
}
7 changes: 4 additions & 3 deletions myCpps/maps.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
3
1.37 4.7 6.37 6.7
3.37 3.7 9.37 7.7
7.37 4.7 10.37 6.7
1 1 5 4
1 5 5 8
1 9 5 12
0
3 changes: 2 additions & 1 deletion myCpps/maps.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
30
Test case #1
Total explored area: 36.00
135 changes: 135 additions & 0 deletions myCpps/mapsOJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include <bits/stdc++.h>

using namespace std;


const int inf = INT_MAX / 2;

const int maxP = 400;

class rect
{
public:
double x1;
double y1;
double x2;
double y2;
};

class line
{
public:
int x;
int y1;
int y2;

bool operator<(const line & temp) const
{
return x < temp.x;
}
};
line _line(int x, int y1, int y2)
{
line temp{x, y1, y2}; return temp;
}

int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
cout << fixed << setprecision(2);

int t = 0;
while (true)
{
int n = 0; cin >> n;
if (n == 0) break;

++t;

vector<rect> a_t(n);
set<double> _set;
for (int i = 0; i <= n - 1; ++i)
{
cin >> a_t[i].x1 >> a_t[i].y1 >> a_t[i].x2 >> a_t[i].y2;
_set.insert(a_t[i].x1);
_set.insert(a_t[i].y1);
_set.insert(a_t[i].x2);
_set.insert(a_t[i].y2);
}

int _i = 0;
vector<double> itod;
map<double, int> dtoi;
for (auto it = _set.begin(); it != _set.end(); ++it)
{
double x = *it;

itod.push_back(x);
dtoi[x] = _i;
++_i;
}

vector<rect> a(n);
for (int i = 0; i <= n - 1; ++i)
{
a[i].x1 = dtoi[a_t[i].x1];
a[i].y1 = dtoi[a_t[i].y1];
a[i].x2 = dtoi[a_t[i].x2];
a[i].y2 = dtoi[a_t[i].y2];
}

vector<line> l;
for (int i = 0; i <= n - 1; ++i)
{
l.push_back(_line(a[i].x1, a[i].y1, a[i].y2));
l.push_back(_line(a[i].x2, a[i].y1, a[i].y2));
}
sort(l.begin(), l.end());

int sizeL = l.size();
vector<double> h(itod.size() + 1, 0.0);
for (int i = 0; i <= sizeL - 2; ++i)
{
int nowX = l[i].x, nextX = l[i + 1].x;

if (nowX == nextX) continue;

vector<int> thisH(maxP, 0);
for (int j = 0; j <= n - 1; ++j)
{
if (a[j].x1 <= nowX && nextX <= a[j].x2)
{
for (int y = a[j].y1; y <= a[j].y2 - 1; ++y)
{
thisH[y] = 1;
}
}
}

for (int y = 0; y <= maxP - 1; ++y)
{
if (thisH[y] == 1)
{
h[i] += (itod[y + 1] - itod[y]);
}
}
}

double ans = 0;
for (int i = 0; i <= sizeL - 2; ++i)
{
int nowX = l[i].x, nextX = l[i + 1].x;

ans += (h[i] * (itod[nextX] - itod[nowX]));
}


cout << "Test case #" << t << '\n';
cout << "Total explored area: " << ans << '\n';

}
cout.flush();
return 0;
}

Loading

0 comments on commit 2b68cc9

Please sign in to comment.