• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LyonLys
愿意在角落唱沙哑的歌 再大声也都是给你 请用心听 不要说话 Contact me via E-mail: lyon.lys@gmail.com
博客园    首页    新随笔    联系   管理    订阅  订阅

hdu 1255 覆盖的面积 (Bruceforce)

Problem - 1255

  暴力统计覆盖超过一次的区域。1y。

代码如下:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <set>
 7 
 8 using namespace std;
 9 
10 typedef pair<double, int> PDBI;
11 multiset<PDBI> pos;
12 #define MPR make_pair
13 #define FI first
14 #define SE second
15 const int N = 1111;
16 double rec[N][4];
17 
18 struct Mark {
19     double x1, x2, y;
20     bool end;
21     Mark() {}
22     Mark(double x1, double x2, double y, bool end) :
23         x1(x1), x2(x2), y(y), end(end) {}
24     bool operator < (Mark x) const { return y < x.y;}
25 } mk[N << 1];
26 
27 int main() {
28     int n, T;
29     cin >> T;
30     while (T-- &&  cin >> n) {
31         for (int i = 0; i < n; i++) {
32             for (int j = 0; j < 4; j++) {
33                 cin >> rec[i][j];
34             }
35             if (rec[i][0] > rec[i][2]) swap(rec[i][0], rec[i][2]);
36             if (rec[i][1] > rec[i][3]) swap(rec[i][1], rec[i][3]);
37             mk[i << 1] = Mark(rec[i][0], rec[i][2], rec[i][1], false);
38             mk[i << 1 | 1] = Mark(rec[i][0], rec[i][2], rec[i][3], true);
39         }
40         sort(mk, mk + (n << 1));
41         pos.clear();
42         if (mk[0].end) {
43             puts("WTF?!!");
44             while (1) {}
45         }
46         pos.insert(MPR(mk[0].x1, 1));
47         pos.insert(MPR(mk[0].x2, -1));
48         multiset<PDBI>::iterator msi;
49         double area = 0.0;
50         for (int i = 1, end = n << 1; i < end; i++) {
51             msi = pos.begin();
52             int cnt = 0;
53             double last, sum = 0.0;
54             while (msi != pos.end()) {
55                 double fi = (*msi).FI;
56                 int se = (*msi).SE;
57                 if (se > 0) {
58                     cnt++;
59                     if (cnt == 2) last = fi;
60                 } else {
61                     cnt--;
62                     if (cnt == 1) sum += fi - last;
63                 }
64                 msi++;
65             }
66             area += sum * (mk[i].y - mk[i - 1].y);
67             if (mk[i].end) {
68                 pos.erase(pos.find(MPR(mk[i].x1, 1)));
69                 pos.erase(pos.find(MPR(mk[i].x2, -1)));
70             } else {
71                 pos.insert(MPR(mk[i].x1, 1));
72                 pos.insert(MPR(mk[i].x2, -1));
73             }
74         }
75         if (pos.size()) {
76             puts("shit!");
77             while (1) {}
78         }
79         printf("%.2f\n", area);
80     }
81     return 0;
82 }
View Code

 

——written by Lyon

posted @ 2013-06-21 06:52  LyonLys  阅读(298)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3