codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

47.md (3754B)


      1 Source: https://codeforces.com/blog/entry/931
      2 
      3 1) Because of small constraints, just iterate *n* from 1 to *T**n* and check ![](https://espresso.codeforces.com/42e32eeab16b0a9de3655a56eff4c400c4e180c4.png)  
      4 
      5 ```
      6 for (int n = 1; n <= Tn; n++)
      7 {
      8     if (n * (n + 1) / 2 == Tn)
      9     {
     10         cout << "YES\n";
     11         return;
     12     }
     13 }
     14 cout << "NO\n";
     15 ```
     16 
     17   
     18  2) Let's consider a graph, where the letters *A*, *B*, *C* are the vertexes and if  *x* < *y*, then the edge *y* -  > *x* exists. After that let's perform [topological sort](https://en.wikipedia.org/wiki/Topological_sorting). If a cycle was found during this operation, put "Impossible" and exit. Otherwise put the answer.  
     19   
     20 Another approach is acceptable because of small constaints (by [Connector](https://codeforces.com/profile/Connector) in russian comments).  
     21 Just iterate over all of 3! permutaioins of the letters and check if they are sorted. If no such permutation, put "Impossible"  
     22   
     23  3) Let's iterate over all of  6! = 720 permutations. For every permutation let's try to put the first 3 words horizontally, the others - vertically:  
     24 
     25 1. hor[0], ver[0] - left-up
     26 2. hor[2], ver[2] - right-down
     27 3. hor[1]: (len(ver[0]) - 1, 0)
     28 4. ver[1]: (0, len(hor[0]) - 1)
     29 
     30 Now let's define N = len(ver[1]), M = len(hor[1]).  
     31 A Conditions for the solution existence  
     32 
     33 1. len(hor[0]) + len(hor[2]) == M + 1 // edges of "eight"
     34 2. len(ver[0]) + len(ver[2]) == N + 1  // edges of "eight"
     35 3. len(hor[0]) >= 3 && len(hor[2]) >= 3 && len(ver[0]) >= 3 && len(ver[2]) >= 3 // "eight" is nondegenerate
     36 4. The letters at start/end of appropriate strings are match
     37 5. The letters on the intersection of hor[1], ver[1] are match
     38 
     39 Now we have the right field of the size N x M, and update the answer  
     40 Note In C++ if you use vector<vector<char> > or vector<string> as the field type, then you can simply use operator "<" for updating.  
     41   
     42 4) Let's consider not the most efficient, but AC algorithm, with  the complexity *O*(*mC**n*5*log*(*C**n*5)).  
     43 Let's consider the 1 answer of the system: <number, v>. The amount of the variants of the password is *C**n**v* - not very large number in constaints of the problem, you can simply generate this variants. Declare this set of variants as current. Now, for the every answer let's generate a set of possible passwords, and let's declare the intersection of this set and current set as current. After *m* iterations we'll have some set. Then we'll erase elements from this set, which were in the answers of the system, and the answer of the problem will be the size of this set.  
     44   
     45   
     46 5) Let's consider an algorightm with complexity *O*((*n* + *m*)*log*(*n* + *m*)).  
     47 Exclude from considiration every wall can't be achieved by canon:  *x* > *v*2 / *g*  
     48 Because of α < =π / 4:  
     49 
     50 1. Function *X**max*(α) is monotonous
     51 2. Function *Y*(α, *x*), when x is fixed, is monotonous
     52 
     53 Such observation allows to assign to each wall a section of the attack angle [α1, α2]. If this canon shoots with angle within this section, it hits the wall. These angles can be obtained by solving equation (it will be biquadratic), but because of monotonous we can use binary search.  
     54 Sort walls by *x*. Now the initial problem has reduced to the problem: for every shoot it is need to obtain minimal index of the wall, when shoot angle is between attack angles for this wall. This problem can be solved by Segment Tree for Minimum with possibility to update on an interval. At first, fill tree with KInf. Next, for every wall let's perform update(α1, α2, index). Then let's iterate over requests. If getMin(α) == KInf, then missle do not hit any wall and hit the land, otherwise it hit the wall with index getMin(α).