CF 241C Mirror Box

Source: Internet
Author: User

Bayan 2012-2013 Elimination Round (acm icpc Rules, English statements

CF, ruanale #105, with T-shirts in the top 100.

However, the rate is increased. When can it be yellow.

Question: a rectangle is given. There are two holes on both sides. There are some mirrors on the upper and lower sides. A ball is emitted from a hole. The mirror on both sides will reflect and finally reach another hole. Each mirror goes through at most once, and each mirror has a certain value. Maximum Value


Since each mirror has at most one time and the start and end points are fixed, you can obtain the reflection distance of each time by enumerating the number of collisions.

There are two types of scenarios, namely, launching from the starting point down and pushing up. Then, based on the parity of the number of collisions, we can get the situation at the ending point.

And the middle is just (I-1) length.

With this, you can start simulating from the launch.

Code is awesome


[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Include <string>
# Include <queue>
# Define inf 1 <30
# Define M 200005
# Define N 200005
# Define maxn300005
# Define eps 1e-10
# Define zero (a) fabs (a) <eps
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mp (a, B) make_pair (a, B)
# Define mem (a, B) memset (a, B, sizeof ())
# Define LL long
# Define lson step <1
# Define rson step <1 | 1
# Define MOD 1000000009.
# Define sqr (a) * ())
# Define Key_value ch [ch [root] [1] [0]
// # Pragma comment (linker, "/STACK: 1024000000,1024000000 ")
Using namespace std;
Int t [100005], f [100005];
Int L = 100000;
Double H = 100.0;
Bool flag [105];
Int main ()
{
Int hl, hr, n, val [105];
While (scanf ("% d", & hl, & hr, & n )! = EOF)
{
Mem (t, 0); mem (f, 0 );
For (int I = 1; I <= n; I ++)
{
Int l, r; char str [10];
Scanf ("% d % s % d", & val [I], str, & l, & r );
If (str [0] = 'F') for (int j = l; j <= r; j ++) F [j] = I;
Else for (int j = l; j <= r; j ++) t [j] = I;
}
Int ans = 0;
For (int I = 1; I <= n; I ++)
{
Double tmp = 0;
If (I & 1) tmp + = hl/H + (I-1) + hr/H;
Else tmp + = hl/H + (I-1) + (H-hr)/H;
Double l = L/tmp;
Double pos = l * hl/H;
Int des = 1;
Int test = 0;
Mem (flag, false );
For (int j = 1; j <= I; j ++)
{
If (des)
{
If (f [(int) floor (pos)] = 0 & f [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = f [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Else
{
If (t [(int) floor (pos)] = 0 & t [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = t [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Pos + = l;
Des = 1-des;
}
Ans = max (ans, test );
Tmp = 0;
If (I & 1) tmp + = (H-hl)/H + (I-1) + (H-hr)/H;
Else tmp + = (H-hl)/H + (I-1) + hr/H;
L = L/tmp;
Pos = l * (H-hl)/H; des = 0;
Test = 0;
Mem (flag, false );
For (int j = 1; j <= I; j ++)
{
If (des)
{
If (f [(int) floor (pos)] = 0 & f [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = f [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Else
{
If (t [(int) floor (pos)] = 0 & t [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = t [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Des = 1-des;
Pos + = l;
}
Ans = max (ans, test );
}
Printf ("% d \ n", ans );
}
Return 0;
}

# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Include <string>
# Include <queue>
# Define inf 1 <30
# Define M 200005
# Define N 200005
# Define maxn300005
# Define eps 1e-10
# Define zero (a) fabs (a) <eps
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mp (a, B) make_pair (a, B)
# Define mem (a, B) memset (a, B, sizeof ())
# Define LL long
# Define lson step <1
# Define rson step <1 | 1
# Define MOD 1000000009.
# Define sqr (a) * ())
# Define Key_value ch [ch [root] [1] [0]
// # Pragma comment (linker, "/STACK: 1024000000,1024000000 ")
Using namespace std;
Int t [100005], f [100005];
Int L = 100000;
Double H = 100.0;
Bool flag [105];
Int main ()
{
Int hl, hr, n, val [105];
While (scanf ("% d", & hl, & hr, & n )! = EOF)
{
Mem (t, 0); mem (f, 0 );
For (int I = 1; I <= n; I ++)
{
Int l, r; char str [10];
Scanf ("% d % s % d", & val [I], str, & l, & r );
If (str [0] = 'F') for (int j = l; j <= r; j ++) F [j] = I;
Else for (int j = l; j <= r; j ++) t [j] = I;
}
Int ans = 0;
For (int I = 1; I <= n; I ++)
{
Double tmp = 0;
If (I & 1) tmp + = hl/H + (I-1) + hr/H;
Else tmp + = hl/H + (I-1) + (H-hr)/H;
Double l = L/tmp;
Double pos = l * hl/H;
Int des = 1;
Int test = 0;
Mem (flag, false );
For (int j = 1; j <= I; j ++)
{
If (des)
{
If (f [(int) floor (pos)] = 0 & f [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = f [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Else
{
If (t [(int) floor (pos)] = 0 & t [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = t [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Pos + = l;
Des = 1-des;
}
Ans = max (ans, test );
Tmp = 0;
If (I & 1) tmp + = (H-hl)/H + (I-1) + (H-hr)/H;
Else tmp + = (H-hl)/H + (I-1) + hr/H;
L = L/tmp;
Pos = l * (H-hl)/H; des = 0;
Test = 0;
Mem (flag, false );
For (int j = 1; j <= I; j ++)
{
If (des)
{
If (f [(int) floor (pos)] = 0 & f [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = f [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Else
{
If (t [(int) floor (pos)] = 0 & t [(int) ceil (pos)] = 0) {test =-1; break ;}
Int id = t [(int) floor (pos)];
If (flag [id]) {test =-1; break ;}
Flag [id] = true; test + = val [id];
}
Des = 1-des;
Pos + = l;
}
Ans = max (ans, test );
}
Printf ("% d \ n", ans );
}
Return 0;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.