28th codeforces competition ends #291Div2

Source: Internet
Author: User
Tags bitset
# NameAChewba logs caandNumberstandardinputoutput1s, second, 256mbx2790cwattoandmechanic ismstandardinputoutput3s, 256MBx895DR2D2andDroidArmystandardinputoutpu

# Name A Chewba ca and Number standard input/output 1 s, 256 MB x3704 B Han Solo and Lazer Gun standard input/output 1 s, 256 MB x2790 C Watto and mechanic standard input/output 3 s, 256 MB x895 D R2D2 and Droid Army standard input/outpu

# Name
A

Chewba certificate ca and Number

Standard input/output

1 s, 256 MB

X3704
B

Han Solo and Lazer Gun

Standard input/output

1 s, 256 MB

X2790
C

Watto and Mechanic

Standard input/output

3 s, 256 MB

X895
D

R2D2 and Droid Army

Standard input/output

2 s, 256 MB

X744


This time I had a lot of time to struggle with question C ......

Codeforces Round #291 (Div. 2)


A. Chewba certificate ca and Number

Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Luke Skywalker gave Chewbacca an integer numberX. Chewbacca isn' t good at numbers but he loves inverting digits in them. Inverting digitTMeans replacing it with digit 9? -?T.

Help Chewbacca to transform the initial numberXTo the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

Input

The first line contains a single integerX(1? ≤?X? ≤? 1018)-the number that Luke Skywalker gave to Chewbacca.

Output

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

Sample test (s)

Input

27

Output

22

Input

4545

Output

4444


I just want to say, "Haha, hahaha, I actually WA four times. Hahaha ...... "

In fact, reading a question is really very important. The number shouldn't contain leading zeroes means that The number does not include leading zeros ...... No ......

Here is a number. You can change any number to (9-current number). You need to obtain the smallest number (but not the leading zero !).

So it is basically a difference between 9 and the current number for all values greater than or equal to 5. Then, note that if the first digit is 0, change it to 9 ...... Sighing, killing people without review

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 main () {string s; cin> s; for (int I = 0; I
        
         

B. Han Solo and Lazer Gun

Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

There areNImperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (X,?Y) On this plane.

Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (X0 ,?Y0). In one shot it can be destroy all the stormtroopers, situated on some line that crosses point (X0 ,?Y0 ).

Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

The gun is the newest partition tion, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

Input

The first line contains three integersN,X0 bytesY0 (1? ≤?N? ≤? 1000 ,? -? 104? ≤?X0 ,?Y0? ≤? 104)-the number of stormtroopers on the battle field and the coordinates of your gun.

NextNLines contain two integers eachXI,YI(? -? 104? ≤?XI,?YI? ≤? 104)-the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrow.stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Output

Print a single integer-the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Sample test (s)

Input

4 0 01 12 22 0-1 -1

Output

2

Input

2 1 21 11 0

Output

1

Note

Explain to the first and second samples from the statement, respectively:


This question is the simplest AC for contestants than A. It tells you the coordinates of the Thundergun and the enemy and how many guns can take them out.

This is probably the case where the number of straight lines drawn from the turret coordinates can penetrate all known points.

After optimization, compare the coordinate system, that is, to regard the point where the fort is located as the origin. If the site has the same slope (the site without slope is also called the same), it is killed in the same attack.

Once Division takes into account the accuracy of floating point numbers to judge the same time it is a headache, so I used the score to represent the slope method, using map to save To represent the slope of a score such as n/m and convert it to the simplest score.

I need to consider the following issues in this method:

1. When one of them is 0, because of the scores of 0 and non-0 numbers, it is either the 0 denominator slope without slope, or, you cannot convert the values of 0 to the same value by finding the maximum common divisor. So once one is 0 and the other is not 0, we can change it to 0/1 and 1/0.

2. When the values are 0, will you be killed ......

3. Here I use map, a great STL. If you don't understand it, map is an array, but the subscript can be anything, here, the table below is a point-to-point score. M [make_pair (a, B)] indicates the subscript.

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;} int x [1001] = {0 }; int y [1001] = {0}; map
                  
                    , Int> m; int main () {int n; cin> x [0]> y [0]; for (int ni = 1; ni <= n; ni ++) {scanf ("% d", & x [ni], & y [ni]); x [ni] = x [ni]-x [0], y [ni] = y [ni]-y [0]; int g =__ gcd (x [ni], y [ni]); if (g = 0) g = Max (x [ni], y [ni]); m [make_pair (x [ni]/g, y [ni]/g)] ++;} cout <
                   
                    

C. Watto and Mechanic

Time limit per test

3 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Watto, the owner of a spare parts store, has recently got an order for the mechanic that can process strings in a certain way. Initially the memory of the mechanic is filledNStrings. Then the mechanic shocould be able to process queries of the following type: "Given stringS, Determine if the memory of the mechanic contains stringTThat consists of the same number of charactersSAnd differs fromSIn exactly one position ".

Watto has already compiled the mechanic, all that's left is to write a program for it and check it on the data consistingNInitial lines andMQueries. He decided to entrust this job to you.

Input

The first line contains two non-negative numbersNAndM(0? ≤?N? ≤? 3 · 105, 0? ≤?M? ≤? 3. 105)-the number of the initial strings and the number of queries, respectively.

Next followNNon-empty strings that are uploaded to the memory of the mechanic.

Next followMNon-empty strings that are the queries to the mechanic.

The total length of lines in the input doesn't exceed 6 · 105. Each line consists only of letters 'A', 'B', 'C '.

Output

For each query print on a single line "YES" (without the quotes), if the memory of the mechanic contains the required string, otherwise print "NO" (without the quotes ).

Sample test (s)

Input

2 3aaaaaacacacaaabaaccacacccaaac

Output

YESNONO


The meaning of the question is to say, first give you n strings, then perform m queries, each time you ask a string, ask if there are any strings in the n strings that have been given earlier to obtain the current string when only one letter is changed.

The problem was solved by Hash. my original idea was to build a tree in the dictionary. Each time I asked the root user to find the target node, I had a different chance, if an existing node cannot be found, it is used and is in the bfs of the current node. However, this method is problematic. For example, a node should actually be different, however, the dictionary tree contains another character string, which is located at this position and cannot be found in my life ...... This is really not the case. So what should Hash do?

The solution report says this:

While adding a string to the set, let's count its polynomial hash and add it to an array. then let's sort this array. now, to know the query answer, let's try to change every symbol in the string and check with binary search if its hash can be found in the array (recounting hashes with O (1) complexity ). if the hash is found in the array, the answer is "YES", otherwise "NO ".

In short, each letter of the hash, sorting, and query string is changed to check whether the hash exists. Over

Code:
#include 
                     
                      typedef long long int lnt;typedef double dou;using namespace std;#define N 600514int nx[N*2][3],spt;int newnode(){for(int i=0;i<3;i++)nx[spt][i]=0;return spt++;}void add(char*s,int p,int*st,int&top){top=0;st[top++]=p;for(int i=0;s[i];i++){int a=s[i]-'a';if(nx[p][a]==0)nx[p][a]=newnode();p=nx[p][a];st[top++]=p;}}set
                      
                        >mp[3];int n,m;char s[N];int r1,r2;int st1[N],t1;int st2[N],t2;int solve(){if(scanf("%d %d",&n,&m)==EOF)return 0;spt=1;r1=newnode();r2=newnode();for(int i=0;i
                       
                        (st1[j],st2[t1-2-j]));}}////////////////////for(int i=0;i
                        
                         (st1[j],st2[t1-2-j]))!=mp[0].end()){flag=1;break;}if(a!=1&&mp[1].find(pair
                         
                          (st1[j],st2[t1-2-j]))!=mp[1].end()){flag=1;break;}if(a!=2&&mp[2].find(pair
                          
                           (st1[j],st2[t1-2-j]))!=mp[2].end()){flag=1;break;}}puts(flag?"YES":"NO");}mp[0].clear();mp[1].clear();mp[2].clear();return 1;}int main(){while(solve());return 0;}
                          
                         
                        
                       
                      
                     

The dictionary tree actually works. Just create a dictionary tree for dfs (why do I use bfs when I am playing ...... Cry)

Code:
# Include
                     
                      
Const int maxnode = 6e5 + 100; const int sigma_size = 3; using namespace std; int n, m; int ch [maxnode] [sigma_size], val [maxnode]; int sz; void init () {memset (ch, 0, sizeof ch); memset (val, 0, sizeof (val); sz = 1;} void insert (char * s) {int u = 0, l = strlen (s); for (int I = 0; I
                      
                       
1) return false; if (p = l) {if (d = 1 & val [rt]) return true; return false ;}for (int I = 0; I
                       
                        


D. R2D2 and Droid Army

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

An armyNDroids is lined up in one row. Each droid is describedMIntegersA1 ,?A2 ,?...,?AM, WhereAIIs the number of details ofI-Th type in this droid's mechanisms. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He hasMWeapons,I-Th weapon can affect all the droids in the army by destroying one detail ofI-Th type (if the droid doesn't have details of this type, nothing happens to it ).

A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at mostKShots. How many shots from the weapon of what type shocould R2-D2 make to destroy the sequence of consecutive droids of maximum length?

Input

The first line contains three integersN,?M,?K(1? ≤?N? ≤? 105, 1? ≤?M? ≤? 5, 0? ≤?K? ≤? 109)-the number of droids, the number of detail types and the number of available shots, respectively.

NextNLines follow describing the droids. Each line containsMIntegersA1 ,?A2 ,?...,?AM(0? ≤?AI? ≤? 108), whereAIIs the number of details ofI-Th type for the respective robot.

Output

PrintMSpace-separated integers, whereI-Th number is the number of shots from the weapon ofI-Th type that the robot shocould make to destroy the subsequence of consecutive droids of the maximum length.

If there are multiple optimal solutions, print any of them.

It is not necessary to make exactlyKShots, the number of shots can be less.

Sample test (s)

Input

5 2 44 01 22 10 21 3

Output

2 2

Input

3 2 41 21 32 2

Output

1 3

Note

In the first test the second, third and fourth droids will be destroyed.

In the second test the first and second droids will be destroyed.


About D ...... I didn't come to check it. At that time, the card C was too cruel, but it seemed to be a queue problem. I first saved a code and a problem-solving report for reference.


To destroy all the droids on a segmentLToR, We need to make sum_m (Max_r cnt [I] [j]) shots, whereCnt[I] [J]-NumberJ-Type details inI-Th droid. let's support two pointers-on the beginning and on the end of the segment, which we want to destroy all the droids on. if we can destroy droids on current segment, let's increase right border of the segment, otherwise increase left border, updating the answer after every segment change. let's use a queue in order to find the segment maximum segment tively.

Code:
#include 
                         
                          #include 
                          
                           #include 
                           #include 
                            
                             #include 
                             
                              #include 
                              
                               #include #include 
                               
                                #include 
                                
                                 #include 
                                 
                                  #include 
                                  
                                   #define ls rt << 1#define rs rt << 1 | 1#define lson ls, l, m#define rson rs, m + 1, r#define getm int m = (l + r) >> 1#define LL long long#define ULL unsigned long long#define pii pair 
                                   
                                    using namespace std;const int N = 100005, mod = 1e9 + 7, M = 100;int n, m, k;int q[N][6], a[N][6], r[6], f[6], e[6];inline void inq (int id, int x) { while (f[id] <= e[id] && a[x][id] >= a[q[e[id]][id]][id]) e[id]--; q[++e[id]][id] = x;}inline void outq (int id, int x) { if (q[f[id]][id] <= x) f[id]++;}inline int jug () { int sum = 0; for (int i = 1; i <= m; i++) { sum += a[q[f[i]][i]][i]; } return sum > k;}inline int read() { int x=0; char ch=getchar(); while(ch<'0'||ch>'9'){ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x;}int main () {// freopen ("in.txt", "r", stdin); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[i][j] = read (); } } for (int i = 1; i <= m; i++) f[i] = 0, e[i] = -1; int res = 0; int pre = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { inq (j, i); } while (pre <= i && jug ()) { for (int j = 1; j <= m; j++) outq(j, pre); pre++; } if (res < i - pre + 1) { res = i - pre + 1; for (int j = 1; j <= m; j++) r[j] = a[q[f[j]][j]][j]; } } for (int i = 1; i <= m; i++) { cout << r[i] << ' '; }}
                                   
                                  
                                 
                                
                               
                              
                             
                            
                          
                         

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.