Codeforces Round #279 (Div. 2) Problem Solving report A. B .C.D. E
A-Team Olympus IAD
Greedy questions .. You can start from the first one.
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; # define LL _ int64int a [6000], B [6000]; int main () {int n, x, y, z, ans, I, j; while (scanf ("% d", & n )! = EOF) {x = y = z = 0; for (I = 0; I
B-Queue
Record the next position with an array to fill the positions of the even and odd numbers respectively.
The position of an even number must start from 0, and the position of an odd number must start from a number without an exit but with an inbound number.
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; # define LL _ int64int next [1100000], a [1100000], out [1100000]; struct node {int u, v ;} fei [1100000]; int main () {int n, I, j, u, v, cnt, pos; while (scanf ("% d", & n )! = EOF) {memset (next,-1, sizeof (next); memset (out, 0, sizeof (out); for (I = 0; I
C-Hacking Cypher
Scan the records from the front and back to record the positions that can be split. It was handled well from the past to the future.
As for the back-to-back, for the k-bit, we can first preprocess the remainder of 10 ^ k on B and the remainder of the first k on B. Then, last digit = total-number of digits represented by the first k x 10 ^ k. So as long as the total number % B = (the number % B in the first k bit) * (10 ^ k % B) % B, the number indicated by the last few digits can be divided into B.
In this way, it can be completed within the complexity of O (n.
It indicates that you are actually a weak scum .. It will be done by others in a short time .. I thought about it for half an hour...
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; # define LL _ int64int a [1100000], B [1100000], c [1100000], d [1100000]; char s [1100000]; int main () {int aa, bb, I, x, len, pos, flag = 0, y; gets (s); scanf ("% d ", & aa, & bb); memset (a, 0, sizeof (a); memset (d, 0, sizeof (d); x = 1; c [1] = 1% bb; for (I = 2; I <= 1000000; I ++) {x = x * 10% bb; c [I] = x ;} len = strlen (s); x = 0; y = 0; for (I = 0; I
D-Chocolate
If the final area is equal, the number of two factors must be equal to the number of three factors. Therefore, we can first obtain the number of two factors and the number of three factors. At this time, we can have two types of operations: remove one 2 or change one 3 to two. so at this time, first change the three larger Parties to 2, so that the remaining three are equal, and then remove the larger number of factors of two to make them equal. Then, you can determine that the area of both parties is equal at this time.
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; # define LL _ int64int main () {int a1, b1, a2, b2, x2, x3, y2, y3, ans, m1, m2, n1, n2; while (scanf ("% d", & a1, & b1, & a2, & b2 )! = EOF) {m1 = a1; m2 = a2; n1 = b1; n2 = b2; x2 = x3 = y2 = y3 = 0; while (! (A1% 2) |! (A1% 3) {if (a1% 2 = 0) {x2 ++; a1/= 2;} if (a1% 3 = 0) {x3 ++; a1/= 3 ;}} while (! (B1% 2) |! (B1% 3) {if (b1% 2 = 0) {x2 ++; b1/= 2;} if (b1% 3 = 0) {x3 ++; b1/= 3 ;}} while (! (A2% 2) |! (A2% 3) {if (a2% 2 = 0) {y2 ++; a2/= 2;} if (a2% 3 = 0) {y3 ++; a2/= 3 ;}} while (! (B2% 2) |! (B2% 3) {if (b2% 2 = 0) {y2 ++; b2/= 2;} if (b2% 3 = 0) {y3 ++; b2/= 3 ;}if (x3> = y3) {x2 + = x3-y3; ans = x3-y3; for (int I = 0; I
= Y2) {for (int I = 0; I
E-Restoring Increasing Sequence
Greedy + simulation.
From the beginning, make sure that each number is the minimum possible value greater than the previous one. When there is an impossible one. It indicates that it is impossible to exist.
Code writing is too frustrating .....
The Code is as follows:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include using namespace std;#define LL __int64char s[110000][10];int main(){ int n, i, x, y, z, len, l, flag, j, k, pos; while(scanf("%d",&n)!=EOF) { getchar(); flag=0; for(i=1; i<=n; i++) { gets(s[i]); } z=0; l=1; s[0][0]='0'; for(i=1; i<=n; i++) { len=strlen(s[i]); if(len
l) { for(j=0; j
s[i-1][j]) { ff=1; for(k=0; k
=0; k--) { if(s[i][k]=='?'&&s[i-1][k]!='9') { s[i][k]=s[i-1][k]+1; pos=k; break; } } if(pos==-1) { flag=1; } else { for(k=0; k
=0;j--) { if(s[i][j]=='?'&&s[i-1][j]!='9') { s[i][j]=s[i-1][j]+1; pos=j; break; } } if(pos==-1) { flag=1; break; } for(j=0;j