UVa837 - Light and Transparencies(排序)

简介: UVa837 - Light and Transparencies(排序)
#include <cstdio>#include <vector>#include <algorithm>#include <cmath>usingnamespacestd;
constdoubleEPS=1e-6;
constintINF=0x3f3f3f3f;
structLine{
doublex1, x2, trans;
booloperator< (constLine&other) const    {
if (fabs(x1-other.x1) >EPS) returnx1<other.x1;
returnx2<other.x2;
    }
};
vector<double>vPoint;
vector<Line>vLine;
voidinput();
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("e:\\uva_in.txt", "r", stdin);
#endifintt;
scanf("%d", &t);
while (t--) {
input();
solve();
if (t) printf("\n");
    }
return0;
}
voidinput()
{
intn;
Lineline;
scanf("%d", &n);
vPoint.clear();
vLine.clear();
for (inti=0; i<n; i++) {
scanf("%lf%*lf%lf%*lf%lf", &(line.x1), &(line.x2), &(line.trans));
//printf("%lf %lf %lf\n", line.x1, line.x2, line.trans);if (line.x1>line.x2) {
swap(line.x1, line.x2);
        }
vPoint.push_back(line.x1);;
vPoint.push_back(line.x2);
vLine.push_back(line);
    }
sort(vPoint.begin(), vPoint.end());
sort(vLine.begin(), vLine.end());
/*printf("size=%d\n", vLine.size());for (size_t i = 0; i < vLine.size(); i++) {printf("%.3lf %.3lf\n", vLine[i].x1, vLine[i].x2);}*/}
voidsolve()
{
vector<Line>ans;
Lineline;
line.x1=-INF, line.x2=vPoint.front(), line.trans=1.0;
ans.push_back(line);
for (inti=0; i<vPoint.size() -1; i++) {
doubletrans=1.0;
for (intj=0; j<vLine.size(); j++) {
if (vPoint[i] >=vLine[j].x1&&vPoint[i] <=vLine[j].x2&&vPoint[i+1] >=vLine[j].x1&&vPoint[i+1] <=vLine[j].x2) {
trans*=vLine[j].trans;
            }
        }
line.x1=vPoint[i], line.x2=vPoint[i+1], line.trans=trans;
ans.push_back(line);
    }
line.x1=vPoint.back(), line.x2=INF, line.trans=1.0;
ans.push_back(line);
printf("%d\n", ans.size());
printf("-inf %.3lf %.3lf\n", ans[0].x2, 1.0);
for (inti=1; i<ans.size() -1; i++) {
printf("%.3lf %.3lf %.3lf\n", ans[i].x1, ans[i].x2, ans[i].trans);
    }
printf("%.3lf +inf %.3lf\n", ans[ans.size() -1].x1, 1.0);
}
目录
相关文章
|
7月前
|
Java
hdu-1312-Red and Black
hdu-1312-Red and Black
35 0
|
7月前
|
算法 测试技术
Big Event in HDU(dp算法)
Big Event in HDU(dp算法)
HDU - 1312 Red and Black(DFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles. Write a program to count the number of black
90 0
|
机器学习/深度学习 Windows
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
104 0
AtCoder Beginner Contest 222 E - Red and Blue Tree(dfs dp)
AtCoder Beginner Contest 222 E - Red and Blue Tree(dfs dp)
123 0
|
算法
PAT (Advanced Level) Practice - 1033 To Fill or Not to Fill(25 分)
PAT (Advanced Level) Practice - 1033 To Fill or Not to Fill(25 分)
99 0
PAT (Advanced Level) Practice - 1135 Is It A Red-Black Tree(30 分)
PAT (Advanced Level) Practice - 1135 Is It A Red-Black Tree(30 分)
103 0
hdu 1312 Red and Black
一个人从@点出发,求他所能到达的'.'的数目,'#'不可走,@本身算1个点。 思路:搜索入门题。
155 0
【1069】The Black Hole of Numbers (20 分)
【1069】The Black Hole of Numbers (20 分) 【1069】The Black Hole of Numbers (20 分)
107 0