upd: ready

This commit is contained in:
2023-11-01 12:33:50 +08:00
parent 85caa0a582
commit c36e8f8337
2 changed files with 34 additions and 16 deletions

View File

@ -385,8 +385,7 @@ void int2048::LeftMoveBy(int L) {
for (int i = this->buf_length - 1; i >= 0; i--) {
(this->val[i] *= kPow10[small_move]) %= int2048::kStoreBase;
if (i - 1 >= 0) {
this->val[i] +=
this->val[i - 1] / kPow10[int2048::kNum - small_move];
this->val[i] += this->val[i - 1] / kPow10[int2048::kNum - small_move];
}
}
this->val[big_move] =
@ -540,7 +539,9 @@ int2048 operator*(int2048 A, const int2048 &B) {
inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
int2048 B(*pB);
int L1 = A.num_length, L2 = B.num_length;
int L1 = (A.num_length + int2048::kNum - 1) / int2048::kNum;
int L2 = (B.num_length + int2048::kNum - 1) / int2048::kNum;
// L1 and L2 are number of blocks
/**
* reference:
* https://github.com/lzyrapx/Competitive-Programming-Docs/blob/master/WC%E8%AE%B2%E8%AF%BE%E8%B5%84%E6%96%99/%E7%90%86%E6%80%A7%E6%84%89%E6%82%A6%E2%80%94%E2%80%94%E9%AB%98%E7%B2%BE%E5%BA%A6%E6%95%B0%E5%80%BC%E8%AE%A1%E7%AE%97%EF%BC%882012WC%EF%BC%89.pdf
@ -555,22 +556,37 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
* 4. calculate [10^(2*n)/B]*A and ajust
*/
if (L2 <= 2) {
;
long long b = B.val[0] + (long long)B.val[1] * int2048::kStoreBase;
__uint128_t c = 0;
for (int i = L1 - 1; i >= 0; i--) {
c = c * int2048::kStoreBase + A.val[i];
A.val[i] = c / b;
c %= b;
}
A.num_length = L1 * int2048::kNum;
const static int kPow10[9] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000};
while (A.num_length > 1 &&
A.val[(A.num_length - 1) / int2048::kNum] /
kPow10[(A.num_length - 1) % int2048::kNum] ==
0)
A.num_length--;
return;
}
if (2 * L2 < L1) {
int delta = L1 - 2 * L2;
A.LeftMoveBy(delta);
A.LeftMoveBy(delta * int2048::kNum);
L1 += delta;
B.LeftMoveBy(delta);
B.LeftMoveBy(delta * int2048::kNum);
L2 += delta;
}
assert(L1 == A.num_length);
assert(L2 == B.num_length);
assert(L1 == (A.num_length + int2048::kNum - 1) / int2048::kNum);
assert(L2 == (B.num_length + int2048::kNum - 1) / int2048::kNum);
assert(2 * L2 >= L1);
int2048 tmp(A);
tmp.LeftMoveBy(233);
tmp.RightMoveBy(233);
assert(tmp == A);
int k = 2;
do {
/* code */
} while (k * 2 <= L2);
}
int2048 &int2048::Divide(const int2048 &B) {
if (this == &B) {

View File

@ -36,7 +36,9 @@ opt_python=[]
if True:
for i in range(0,10):
val=randint(-10**100,10**100)
val=randint(-10**15,10**15)
if i==0:
val=randint(-10**100,10**100)
opt_cpp.append("a_"+str(i)+"=int2048(\""+str(val)+"\");")
opt_python.append("a_"+str(i)+"="+str(val))
opt_cpp.append("a_"+str(i)+".print(); puts(\"\");")
@ -45,8 +47,8 @@ if True:
if True:
for i in range(1):
aid=randint(0,9)
bid=randint(0,9)
cid=randint(0,9)
bid=randint(0,0)
cid=randint(1,9)
op='/'
bflag="+"
if randint(0,1)==0:
@ -80,7 +82,7 @@ for opt in opt_cpp:
print(opt,file=sourc_cpp)
print(code_cpp_suf,file=sourc_cpp)
sourc_cpp.close()
system("g++ /tmp/3.cpp -I /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/ -L /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/src/ -lint2048 -g -o /tmp/3")
system("g++ /tmp/3.cpp -I /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/ -L /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/src/ -lint2048 -g -fsanitize=address -o /tmp/3")
system("/tmp/3 > /tmp/3_cpp.out")
sourc_python=open("/tmp/3.py","w")