[codeforces 241]C. Mirror Box

试题描述

Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights hl and hr centimeters above the floor. The picture below shows what the box looks like.

In the game, you will be given a laser gun to shoot once. The laser beam must enter from one hole and exit from the other one. Each mirror has a preset number vi, which shows the number of points players gain if their laser beam hits that mirror. Also — to make things even funnier — the beam must not hit any mirror more than once.

Given the information about the box, your task is to find the maximum score a player may gain. Please note that the reflection obeys the law "the angle of incidence equals the angle of reflection".

输入

The first line of the input contains three space-separated integers hl, hr, n (0 < hl, hr < 100, 0 ≤ n ≤ 100) — the heights of the holes and the number of the mirrors.

Next n lines contain the descriptions of the mirrors. The i-th line contains space-separated vi, ci, ai, bi; the integer vi (1 ≤ vi ≤ 1000) is the score for the i-th mirror; the character ci denotes i-th mirror's position — the mirror is on the ceiling if ci equals "T" and on the floor if ci equals "F"; integers ai and bi (0 ≤ ai < bi ≤ 105) represent the x-coordinates of the beginning and the end of the mirror.

No two mirrors will share a common point. Consider that the x coordinate increases in the direction from left to right, so the border with the hole at height hl has the x coordinate equal to 0 and the border with the hole at height hr has the x coordinate equal to 105.

输出

The only line of output should contain a single integer — the maximum possible score a player could gain.

输入示例

 T
F
T
F
F
F
F
T
T

输出示例


数据规模及约定

见“输入

题解

因为光线不能两次触碰到同一面镜子,所以拐点不会超过 n 个,我们不妨枚举拐点个数。确定了拐点个数后,我们设 t 是一个完整斜边(从底边反射上来再触碰到顶)在底边上投影的距离,不难列出一个一元一次方程,把 t 解出来后再遍历一遍每个镜子检查答案是否合法,合法就更新最优得分。枚举拐点个数 O(n),检查合法性 O(n),总时间复杂度 O(n2).

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 110
#define len 100000
const double eps = 1e-6;
int h1, h2, n, cu, cd, ans;
struct Mirror {
int v, l, r;
bool operator < (const Mirror& t) const { return l < t.l; }
} up[maxn], down[maxn]; void check(bool cur, double t, double st) {
bool ok = 0;
int lu = 1, lastu = 0, ld = 1, lastd = 0, tmp = 0;
for(; st - len < eps && (lu <= cu || ld <= cd);) {
if(cur) {
while(lu < cu && st - up[lu].r > eps) lu++;
if(st - up[lu].l < eps || st - up[lu].r > eps || lu == lastu) return ;
tmp += up[lu].v; lastu = lu;
}
else {
while(ld < cd && st - down[ld].r > eps) ld++;
if(st - down[ld].l < eps || st - down[ld].r > eps || ld == lastd) return ;
tmp += down[ld].v; lastd = ld;
}
st += t; cur ^= 1;
}
ans = max(ans, tmp);
return ;
} int main() {
h1 = read(); h2 = read(); n = read();
for(int i = 1; i <= n; i++) {
int v = read();
char tp = getchar();
while(!isalpha(tp)) tp = getchar();
if(tp == 'T') up[++cu].v = v, up[cu].l = read(), up[cu].r = read();
if(tp == 'F') down[++cd].v = v, down[cd].l = read(), down[cd].r = read();
} sort(up + 1, up + cu + 1);
sort(down + 1, down + cd + 1);
for(int k = 0; k <= n; k++) {
// down 0; up 1;
double t;
if(k & 1) {
t = (double)len / ((double)h1 / 100.0 + (100.0 - h2) / 100.0 + k);
check(0, t, t * h1 / 100.0);
t = (double)len / ((100.0 - h1) / 100.0 + (double)h2 / 100.0 + k);
check(1, t, t * (100.0 - h1) / 100.0);
}
else {
t = (double)len / ((double)h1 / 100.0 + (double)h2 / 100.0 + k);
check(0, t, t * h1 / 100.0);
t = (double)len / ((100.0 - h1) / 100.0 + (100.0 - h2) / 100.0 + k);
check(1, t, t * (100.0 - h1) / 100.0);
}
} printf("%d\n", ans); return 0;
}

[codeforces 241]C. Mirror Box的更多相关文章

  1. [codeforces 241]A. Old Peykan

    [codeforces 241]A. Old Peykan 试题描述 There are n cities in the country where the Old Peykan lives. The ...

  2. CodeForces 388A Fox and Box Accumulation (模拟)

    A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Cie ...

  3. codeforces A. Fox and Box Accumulation 解题报告

    题目链接:http://codeforces.com/problemset/problem/388/A 题目意思:有 n 个 boxes,每个box 有相同的 size 和 weight,但是stre ...

  4. Codeforces 388A - Fox and Box Accumulation

    388A - Fox and Box Accumulation 思路: 从小到大贪心模拟. 代码: #include<bits/stdc++.h> using namespace std; ...

  5. Codeforces 1182D Complete Mirror [树哈希]

    Codeforces 中考考完之后第一个AC,纪念一下qwq 思路 简单理解一下题之后就可以发现其实就是要求一个点,使得把它提为根之后整棵树显得非常对称. 很容易想到树哈希来判结构是否相同,而且由于只 ...

  6. Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序

    题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...

  7. 「CF578F」 Mirror Box

    description CF578F solution 考虑转化题目的要求 1.对于任意一条边,都存在一条从界垂直射入的光线,经过反射穿过这条边. 当图中有环时,环内的边一定不满足条件,而在不存在环时 ...

  8. [cf578F]Mirror Box

    构造如下一张无向图: 1.点集大小为$(n+1)(m+1)$,即所有格点 2.边集大小为$nm$,即所有镜子所连结的两个格点 对于一个确定的镜子状态,即可确定上图,那么来考虑什么样的图是合法的 结论: ...

  9. html跳动的心实现代码

    <style>         .box{             width: 200px;             height: 400px;             positio ...

随机推荐

  1. Bootstrap系列 -- 26. 下拉菜单标题

    Bootstrap下拉菜单中使用 dropdown-header 来显示菜单标题,和上一篇说道的分割线一样 <div class="dropdown"> <but ...

  2. 13.C#分部类型和静态类(七章7.1-7.2)

    再大的东西不去找,也就没了,再小的知识不去记,也就忘了.今天来写一写C#中的分部类型和静态工具类,这些两个概念可能在我们的日常使用过程中都使用过,可能大家对这些内容觉得这些不是应该有的东西嘛,那就来复 ...

  3. C#基础知识系列九(对IEnumerable和IEnumerator接口的糊涂认识)

    前言 IEnumerable.IEnumerator到现在为止对这两个接口还是不太理解,不理解但是自己总是想着试着要搞明白,毕竟自己用的少,所以在此先记录一下.以备自己日后可以来翻查,同时也希望园子里 ...

  4. 第二十一课:js属性操作的兼容性问题

    上一课主要讲了属性的概念,用法,固有属性和自定义属性的区别,class属性操作的方法等,这一课主要讲一些有关属性操作的兼容性问题. IE6-IE8在一些表示URL的属性会返回补全的改过编码的路径,比如 ...

  5. Nodejs学习笔记(五)--- Express安装入门与模版引擎ejs

    目录 前言 Express简介和安装 运行第一个基于express框架的Web 模版引擎 ejs express项目结构 express项目分析 app.set(name,value) app.use ...

  6. ”耐撕“团队 2016.3.21 站立会议3 2 1 GO!

    ”耐撕“团队 2016.3.21 站立会议 时间:2016.3.21  ① 17:20-17:45  ②17:55-18:10  总计40分钟 成员: Z 郑蕊 * 组长 (博客:http://www ...

  7. Callable、Future和FutureTask

    创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口.这2种方式都有一个缺陷就是:在执行完任务之后无法获取执行结果. 如果需要获取执行结果,就必须通过共享变量或者使用线 ...

  8. JSP中<base href="<%=basePath%>">的作用

    来源于:http://fanshuyao.iteye.com/blog/2097229 首先了解是什么是<base href=""> <base href=&qu ...

  9. 史上最全的HTML、CSS知识点总结,浅显易懂。

    来源于:http://blog.csdn.net/qiushi_1990/article/details/40260447 一,html+css基础1-1Html和CSS的关系学习web前端开发基础技 ...

  10. .net架构设计读书笔记--第一章 基础

    第一章 基础 第一节 软件架构与软件架构师  简单的说软件架构即是为客户构建一个软件系统.架构师随便软件架构应运而生,架构师是一个角色. 2000年9月ANSI和IEEE发布了<密集性软件架构建 ...