[09 noip simulation] Light

Source: Internet
Author: User

From my Baidu Space

Light. PAS/C/CPP)

[Description]

On an infinitely long road, there is a line of infinite street lights numbered 1, 2, 3, 4 ,.......

Each lamp has only two possible states: on or off. If you click the switch of a certain lamp, the status of the lamp will change. If it is turned on, it will turn off. If it is disabled, it will be turned on.

At the beginning, all the lights were turned off.

James can perform the following operations each time:

Specify two numbers, a and T (A is a real number and T is a positive integer ). Enter [a], [2 * A], [3 * A],…, The switch of the [T * A] lamp is one by one. [K] indicates the integer part of the real number K.

After James performed N operations, James suddenly found that only one lamp was on at this time, and James wanted to know the number of the lamp, but this light is too far away from Xiaoming, and James cannot see the number.

Fortunately, James remembers n previous operations. So James found you. Could you help him calculate the number of the light on?

[Input format]

The first row is a positive integer N, indicating N operations.

Next there are n rows, two numbers in each row, AI and Ti. Where AI is a real number, there must be 6 digits after the decimal point, Ti is a positive integer.

[Output format]

Only one positive integer, the number of the light on.

[Input example]

3

1.618034 13

2.618034 7

1.000000 21

[Output example]

20

[Data scale]

Note T = t1 + T2 + T3 + ...... + Tn.

For 30% of data, T <= 1000

For 80% of data, T <= 200000

For 100% of data, T <= 2000000

For 100% of data, n <=, 1 <= AI <, 1 <= Ti <= T

Data guarantee: After N operations, only one light is on and no error is required.

The following is a program provided by myself. It is just a simulation. If you want Daniel to see it, you can instruct the younger brother how to optimize it ~

Program light (input, output );
VaR
I, i1, j, k, n, T1, Z1: longint;
Z: real;
A: array [1 .. 10000000] of real;
B: array [1 .. 10000000] of Boolean;
C: array [1 .. 1000] of integer;
T: array [1 .. 10000000] of integer;

Function Change (Z: Real): longint;
VaR I1: longint;
Begin
I1: = 0;
While I1 <Z do Inc (I1 );
Change: = I1;
End; {change}

Begin
Assign (input, 'light. in ');
Reset (input );
Assign (output, 'light. out ');
Rewrite (output );

Readln (N );
For I: = 1 to n do
Readln (A [I], t [I]);
Close (input );

K: = 1;
For I: = 1 to n do writeln (A [I], '', t [I]);
Fillchar (B, sizeof (B), false );
For I: = 1 to n do begin
For J: = 1 to T [I] Do begin
Z: = int (A [I] * j );
Z1: = change (z );
Write ('deng ----> ', Z1 ,'');
If Z1> K then K: = Z1;
B [Z1]: = Not (B [Z1]);
For I1: = 1 to k do write (B [I1]: 8 );
Writeln;
End;
End; {doit}
T1: = 0;
For I: = 1 to k do
If B [I] Then begin
T1: = t1 + 1;
C [T1]: = I;
End;
For I: = 1 to T1 do writeln (C [I]);
Close (output );
End.

Some test outputs are not removed

There were only seven points on the left, and later I found that it seemed to be simplified, and the following program passed 10 points.
Program light (input, output );
VaR
I, i1, j, k, n, T1, Z1: longint;
Z: real;
A: array [1 .. 200000000] of real;
B: array [1 .. 200000000] of Boolean;
C: array [1 .. 1000] of integer;
T: array [1 .. 200000000] of integer;

Function Change (Z: Real): longint;
VaR I1: longint;
Begin
I1: = 0;
While I1 <Z do Inc (I1 );
Change: = I1;
End; {change}

Begin
Assign (input, 'light. in ');
Reset (input );
Assign (output, 'light. out ');
Rewrite (output );

Readln (N );
For I: = 1 to n do
Readln (A [I], t [I]);
Close (input );

K: = 1;
Fillchar (B, sizeof (B), false );
For I: = 1 to n do begin
For J: = 1 to T [I] Do begin
Z: = int (A [I] * j );
Z1: = change (z );
If Z1> K then K: = Z1;
B [Z1]: = Not (B [Z1]);
End;
End; {doit}
T1: = 0;
For I: = 1 to k do
If B [I] Then begin
T1: = t1 + 1;
C [T1]: = I;
End;
For I: = 1 to T1 do writeln (C [I]);
Close (output );
End.

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.