Codeforces Round #137 (Div. 2)

Source: Internet
Author: User

It's not a difficult task ~~~

A. Shooshuns and Sequence


If you want to use YY, it must first be the same after k. Otherwise, it will not be completed in any case.

Then we need to check whether there are several consecutive identical values before k.

 


B. Cosmic Tables


Directly, the two arrays record the current position of each row and the current position of each column.

 


C. indexing Fractions


After a prime factor is decomposed, do not combine the prime factor, which is prone to errors. One is easy to get out of the upper bound, and the other is easy to count too many.

Obviously, the new score is about to get the original score, so the number remains unchanged. We can keep the remaining score.


[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Define inf 1 <27
# Define M 100005
# Define N 10000005
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof (B ))
# Define LL long
Using namespace std;
Int prime [N] = {0}, c1 [N], c2 [N];
Int n, m, a [M], B [M];
Void Prime (){
For (int I = 2; I <N; I ++ ){
If (prime [I]) continue;
For (int j = 2; j * I <N; j ++)
Prime [I * j] = 1;
}
}
Void split (int num, int c []) {
For (int I = 2; I * I <= num & prime [num]; I ++ ){
While (num % I = 0 ){
C [I] ++;
Num/= I;
}
}
If (num> 1) c [num] ++;
}
Void print (int num, int c []) {
Int tmp = 1;
For (int I = 2; I * I <= num & prime [num]; I ++ ){
// Cout <I <"" <c [I] <endl;
While (num % I = 0 ){
If (c [I]) {c [I] --; tmp * = I ;}
Num/= I;
}
}
If (num> 1 & c [num]) {c [num] --; tmp * = num ;}
Printf ("% d", tmp );
}
Int main (){
Prime ();
While (scanf ("% d", & n, & m )! = EOF ){
Mem (c1, 0); mem (c2, 0 );
For (int I = 0; I <n; I ++ ){
Scanf ("% d", & a [I]);
Split (a [I], c1 );
}
For (int I = 0; I <m; I ++ ){
Scanf ("% d", & B [I]);
Split (B [I], c2 );
}
For (int I = 2; I <N; I ++ ){
Int mm = min (c1 [I], c2 [I]);
C1 [I]-= mm; c2 [I]-= mm;
}
Printf ("% d \ n", n, m );
For (int I = 0; I <n; I ++)
Print (a [I], c1 );
Printf ("\ n ");
For (int I = 0; I <m; I ++)
Print (B [I], c2 );
Printf ("\ n ");
}
Return 0;
}

# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Define inf 1 <27
# Define M 100005
# Define N 10000005
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof (B ))
# Define LL long
Using namespace std;
Int prime [N] = {0}, c1 [N], c2 [N];
Int n, m, a [M], B [M];
Void Prime (){
For (int I = 2; I <N; I ++ ){
If (prime [I]) continue;
For (int j = 2; j * I <N; j ++)
Prime [I * j] = 1;
}
}
Void split (int num, int c []) {
For (int I = 2; I * I <= num & prime [num]; I ++ ){
While (num % I = 0 ){
C [I] ++;
Num/= I;
}
}
If (num> 1) c [num] ++;
}
Void print (int num, int c []) {
Int tmp = 1;
For (int I = 2; I * I <= num & prime [num]; I ++ ){
// Cout <I <"" <c [I] <endl;
While (num % I = 0 ){
If (c [I]) {c [I] --; tmp * = I ;}
Num/= I;
}
}
If (num> 1 & c [num]) {c [num] --; tmp * = num ;}
Printf ("% d", tmp );
}
Int main (){
Prime ();
While (scanf ("% d", & n, & m )! = EOF ){
Mem (c1, 0); mem (c2, 0 );
For (int I = 0; I <n; I ++ ){
Scanf ("% d", & a [I]);
Split (a [I], c1 );
}
For (int I = 0; I <m; I ++ ){
Scanf ("% d", & B [I]);
Split (B [I], c2 );
}
For (int I = 2; I <N; I ++ ){
Int mm = min (c1 [I], c2 [I]);
C1 [I]-= mm; c2 [I]-= mm;
}
Printf ("% d \ n", n, m );
For (int I = 0; I <n; I ++)
Print (a [I], c1 );
Printf ("\ n ");
For (int I = 0; I <m; I ++)
Print (B [I], c2 );
Printf ("\ n ");
}
Return 0;
}
D. Olympus


Readforces ~~~~ After reading this, the sorting is greedy. The question says that there must be a group of values greater than k, so the optimal value is 1.


E. Decoding Genome


Simple question ~~ Construction matrix, Fast Power Multiplication


[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Define inf 1 <27
# Define M 100005
# Define N 55
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof (B ))
# Define LL long
# Define MOD 1000000007.
Using namespace std;
Struct Matrix {
LL m [N] [N];
} Init;
LL n, k, m;
Int ID (char ch ){
If (ch> = 'A' & ch <= 'Z') return ch-'A ';
Else return ch-'A' + 26;
}
Matrix Mult (Matrix m1, Matrix m2, int n ){
Matrix ans;
For (int I = 0; I <n; I ++)
For (int j = 0; j <n; j ++ ){
Ans. m [I] [j] = 0;
For (int k = 0; k <n; k ++)
Ans. m [I] [j] = (ans. m [I] [j] + m1.m [I] [k] * m2.m [k] [j]) % MOD;
}
Return ans;
}
Matrix Pow (Matrix m1, LL B, int n ){
Matrix ans;
For (int I = 0; I <n; I ++)
For (int j = 0; j <n; j ++)
Ans. m [I] [j] = (I = j );
While (B ){
If (B & 1)
Ans = Mult (ans, m1, n );
M1 = Mult (m1, m1, n );
B> = 1;
}
Return ans;
}
Void debug (Matrix m1, int n ){
For (int I = 0; I <n; I ++ ){
For (int j = 0; j <n; j ++)
Printf ("% I64d", m1.m [I] [j]);
Printf ("\ n ");
}
}
Int main (){
While (scanf ("% I64d % d", & n, & k, & m )! = EOF ){
For (int I = 0; I <k; I ++) for (int j = 0; j <k; j ++) init. m [I] [j] = 1;
While (m --){
Char str [5];
Scanf ("% s", str );
Init. m [ID (str [0])] [ID (str [1])] = 0;
}
// Debug (init, k );
Init = Pow (init, n-1, k );
// Debug (init, k );
LL ans = 0;
For (int I = 0; I <k; I ++)
For (int j = 0; j <k; j ++)
Ans = (ans + init. m [I] [j]) % MOD;
Printf ("% I64d \ n", ans );
}
Return 0;
}

# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Define inf 1 <27
# Define M 100005
# Define N 55
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof (B ))
# Define LL long
# Define MOD 1000000007.
Using namespace std;
Struct Matrix {
LL m [N] [N];
} Init;
LL n, k, m;
Int ID (char ch ){
If (ch> = 'A' & ch <= 'Z') return ch-'A ';
Else return ch-'A' + 26;
}
Matrix Mult (Matrix m1, Matrix m2, int n ){
Matrix ans;
For (int I = 0; I <n; I ++)
For (int j = 0; j <n; j ++ ){
Ans. m [I] [j] = 0;
For (int k = 0; k <n; k ++)
Ans. m [I] [j] = (ans. m [I] [j] + m1.m [I] [k] * m2.m [k] [j]) % MOD;
}
Return ans;
}
Matrix Pow (Matrix m1, LL B, int n ){
Matrix ans;
For (int I = 0; I <n; I ++)
For (int j = 0; j <n; j ++)
Ans. m [I] [j] = (I = j );
While (B ){
If (B & 1)
Ans = Mult (ans, m1, n );
M1 = Mult (m1, m1, n );
B> = 1;
}
Return ans;
}
Void debug (Matrix m1, int n ){
For (int I = 0; I <n; I ++ ){
For (int j = 0; j <n; j ++)
Printf ("% I64d", m1.m [I] [j]);
Printf ("\ n ");
}
}
Int main (){
While (scanf ("% I64d % d", & n, & k, & m )! = EOF ){
For (int I = 0; I <k; I ++) for (int j = 0; j <k; j ++) init. m [I] [j] = 1;
While (m --){
Char str [5];
Scanf ("% s", str );
Init. m [ID (str [0])] [ID (str [1])] = 0;
}
// Debug (init, k );
Init = Pow (init, n-1, k );
// Debug (init, k );
LL ans = 0;
For (int I = 0; I <k; I ++)
For (int j = 0; j <k; j ++)
Ans = (ans + init. m [I] [j]) % MOD;
Printf ("% I64d \ 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.