27th codeforces competition ends #288Div2

Source: Internet
Author: User
Problems # NameAPashaandPixelsstandardinputoutput2s, bytes. 5 s, 256MBx2848CAnyaandGhostsstandardinputoutput2s, 256MBx1671 this time out the first three questions, the original is the third-digit Av

Problems # Name A Pasha and Pixels standard input/output 2 s, 256 MB x3234 B Anton and currency you all know standard input/output 0.5 s, 256 MB x2848 C Anya and Ghosts standard input/output 2 s, 256 MB x1671 this time out the first three questions, the original third-digit Av

Problems

# Name
A

Pasha and Pixels

Standard input/output

2 s, 256 MB

X3234
B

Anton and currency you all know

Standard input/output

0.5 s, 256 MB

X2848
C

Anya and Ghosts

Standard input/output

2 s, 256 MB

X1671


This time I got the first three questions. I added 100 points to the third Avator and changed it to the second one. Now I have 1650 + three IDs. Congratulations! I hope I can support it for a few more days ......


A. Pasha and Pixels

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.

Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consistingNRowMPixels in each row. initially, all the pixels are colored white. in one move, Pasha can choose any pixel and color it black. in particle, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. pasha loses the game when a 2? ×? 2 square consisting of black pixels is formed.

Pasha has made a planKMoves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbersIAndJ, Denoting respectively the row and the column of the pixel to be colored on the current move.

Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2? ×? 2 square consisting of black pixels is formed.

Input

The first line of the input contains three integersN,?M,?K(1? ≤?N,?M? ≤? 1000, 1? ≤?K? ≤? 105)-the number of rows, the number of columns and the number of moves that Pasha is going to perform.

The nextKLines contain Pasha's moves in the order he makes them. Each line contains two integersIAndJ(1? ≤?I? ≤?N, 1? ≤?J? ≤?M), Representing the row number and column number of the pixel that was painted during a move.

Output

If Pasha loses, print the number of the move when the 2? ×? 2 square consisting of black pixels is formed.

If Pasha doesn' t lose, that is, no 2? ×? 2 square consisting of black pixels is formed during the givenKMoves, print 0.

Sample test (s)

Input

2 2 41 11 22 12 2

Output

4

Input

2 3 62 32 21 32 21 21 1

Output

5

Input

5 3 72 31 21 14 13 15 33 2

Output

0



Give you an n * m chessboard. Every time you go to the grid, it will be hacked. Next, there will be k steps, each step tells you which grid (Row/Col coordinate) I took in this step, and requires that the 2X2 black square appear for the first time when the first step is taken, the output value is 0.

Looking at the data range, it seems that ...... The simulation is completely stress-free.

We will really give a board. Every step we take, we will mark this grid mp [a] [B] = 1, and then find the top left, top right, bottom right, the four 2X2 squares are not all black. If yes, the output is then return. If not, continue ~

Code:
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include using namespace std; # define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) bool cmp (const int a, const int B) {return a> B;} int mp [1002] [1002] = {0 }; bool judge (int r, int c) {if (mp [r-1] [c] = 1) {if (mp [r] [C-1] = 1) {if (mp [r-1] [C-1] = 1) return true;} if (mp [r] [c + 1] = 1) {if (mp [r-1] [c + 1] = 1) return true ;}} if (mp [r + 1] [c] = 1) {if (mp [r] [C-1] = 1) {if (mp [r + 1] [C-1] = 1) return true ;} if (mp [r] [c + 1] = 1) {if (mp [r + 1] [c + 1] = 1) return true ;}} return false;} int main () {int n, m, k; cin> n> m> k; for (int I = 1; I <= k; I ++) {int r, c; scanf ("% d", & r, & c); mp [r] [c] = 1; if (judge (r, c) {cout <
        
         

B. Anton and currency you all know

Time limit per test

0.5 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Berland, 2016. the exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.

Reliable sources have informed the specified er Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. it is guaranteed that today the exchange rate is an odd positive integerN. Help Anton to determine the exchange rate of currency you all know for tomorrow!

Input

The first line contains an odd positive integerN-The exchange rate of currency you all know for today. The length of numberN'S representation is within range from 2 to 105, intrusive. The representationNDoesn' t contain any leading zeroes.

Output

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print? -? 1.

Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. this shoshould be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. exchange rate representation shocould not contain leading zeroes.

Sample test (s)

Input

527

Output

572

Input

4573

Output

3574

Input

1357997531

Output

-1



Give a long number, at least two digits, and an odd number at most 10 in five locations, so that you can change the two digits to the largest and even numbers in various variables and output them, if not, output-1.

Obviously, the last digit determines the parity. Therefore, the last digit is the last digit in the two digits to be swapped. What we cannot do is that there is no even number in the number, after special cases are excluded, we will consider how to maximize.

Because the number is too large, we cannot directly add or subtract or even record the maximum value, but we can find it by writing it on paper. It is obvious that the difference between the change and the change must be a99999... the number of 999B, and AB as a two digit is the two digits before and after the replacement of the two digits of the difference, that is, 10 * B + A-10 * A-B = 9 * (B-A ), we don't even need to connect to 9 ...... We can simply record it through positive and negative (zf), number of 9 (digit), and difference (sub ~ Why do I propose positive and negative messages !!! You can use an int to directly calculate the positive and negative values! I'm so stupid ...... Really ......

Code:
# Include# Include
           
            
# Include
            
             
# Include
             
              
# Include
              
               
# Include
               
                 # Include
                
                  # Include
                 
                   # Include using namespace std; # define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) bool cmp (const int a, const int B) {return a> B;} string s; string ans; int zf, digit, sub; int tzf, td, ts, len; // temp zf, dig, submap
                  
                    M; void update (int pos) {zf = tzf; digit = td; sub = ts; ans = s; char temp = ans [pos]; ans [pos] = ans [len-1]; ans [len-1] = temp;} int main () {m. clear (); cin> s; len = s. length (); int tail = s [len-1]-'0'; for (int I = 0; I
                   
                     : Iterator it = m. begin (); it! = M. end (); ++ it) {// cout <it-> first <"=>" <it-> second <'\ n '; int pos = it-> first; int now = s [pos]-'0'; tzf = 1; ts = tail-now; // * 9 skipped td = s. length ()-pos; if (ts <0) {tzf =-1; ts =-ts;} if (tzf> zf) update (pos ); else if (tzf = 1 & zf = 1) {if (td> digit) update (pos); else if (td = digit) {if (ts> sub) update (pos) ;}} else if (tzf =-1 & zf =-1) {if (td
                    
                     

Another Code:
#include
                      
                       #include
                       
                        int n,i,x,minpos=-1;char a[100010],t;int main(){    scanf("%s",a);    n=strlen(a);    for(i=0;i
                        
                         a[i]){                t = a[n-1] , a[n-1] = a[i] , a[i] = t;                printf("%s\n",a);                return 0;            }            else{                minpos = i;            }        }    }    if(minpos==-1){        printf("-1\n");    }    else{        t = a[n-1] , a[n-1] = a[minpos] , a[minpos] = t;        printf("%s\n",a);        return 0;    }}
                        
                       
                      


C. Anya and Ghosts

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Anya loves to watch horror movies. In the best traditions of horror, she will be visitedMGhosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactlyTSeconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactlyTSeconds and then goes out and can no longer be used.

For each ofMGhosts Anya knows the time at which it comes:I-Th visit will happenWISeconds after midnight, allWI'S are distinct. Each visit lasts exactly one second.

What is the minimum number of candles Anya shocould use so that during each visit, at leastRCandles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. that means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

Input

The first line contains three integersM,T,R(1? ≤?M,?T,?R? ≤? 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that shoshould burn during each visit.

The next line containsMSpace-separated numbersWI(1? ≤?I? ≤?M, 1? ≤?WI? ≤? (300),I-Th of them repesents at what second after the midnightI-Th ghost will come. AllWI'S are distinct, they follow in the strictly increasing order.

Output

If it is possible to make at leastRCandles burn during each visit, then print the minimum number of candles that Anya needs to light for that.

If that is impossible, print? -? 1.

Sample test (s)

Input

1 8 310

Output

3

Input

2 10 15 8

Output

1

Input

1 1 310

Output

-1

Note

Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.

It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.

In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.

In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.

In the third sample test the answer is? -? 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.


Anna is a little girl. m's ghost is coming to Anna's house in the evening (the ghost visit time is given in ascending order). The girl can light a candle every second and the candle can burn for t S, when a ghost arrives at her house, she needs at least r candles to burn and asks how many candles can be used to tide over the storm.

First of all, we need to consider "-1", that is, what is the situation? The candle is lit every second, but the r candle cannot be lit at any second. Then, m

When m> = r, we burn a candle at the last second of any candle burning. When the candle is extinguished, the new candle burns for the first second, the r candle state can be continued. First, when the first ghost came, it was obvious that we started pushing forward from the first second of the ghost to avoid wasting the candle duration, from the first second to the first r second, the candle was lit. At this time, when the first ghost arrived, the candle was r and the remaining burning time was the largest, what are you asking me if the first second the ghost will come? Carefully read the question:That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

Then we use the lgt (light) array to record the current brightness of each second. In order to know when a candle is destroyed, we will assign a value of-1 to the lgt [current number of seconds + t] at the time of ignition, so that when dp is pushed there, it will automatically subtract one to the effect of reduction, we started pushing from the first second. When we met a ghost, we should see that the current light is not enough. If it was not enough, we would start to fill the candle in the first second. Then, all the way back, the number of candles would inevitably be the smallest, it's also a greedy dp.

Code:
#include 
                      
                        #include 
                       
                        #include 
                        
                         #include 
                         
                          #include 
                          
                           #include 
                           
                            #include 
                            
                             #include using namespace std;#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))bool cmp(const int a, const int b){return a > b;}int vit[666]={0};int lgt[666]={0};//degree of lightint main(){int c=0;int m,t,r;cin>>m>>t>>r;if(t
                             
                            
                           
                          
                         
                        
                       
                      

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.