wmh123

1765

JimmyHu

_Null_
YunaArtemis
Free_Man
whale77

wen11
Iamyou_9
Allen5168

tanbensheng
AcWing_czy
no_one

lillllllllll
2850g

Shmilysw

wmh123
2天前


#include <iostream>
//#include <cstdio>

using namespace std;

const int N = 1010;

int n, m, q;
int s[N][N];//二维数组

int main()
{
ios::sync_with_stdio(0);
cin >> n >> m >> q;

for (int i = 1; i <= n; i ++ ) //输入矩阵
{
for (int j = 1; j <= m; j ++ )
{
cin >> s[i][j];
}

}

for (int i = 1; i <= n; i ++ )//求和后矩阵
{
for (int j = 1; j <= m; j ++ )
{
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
//二维前缀和预处理公式
}
}

while (q -- )
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] << endl;
//以(x1, y1)为左上角，(x2, y2)为右下角的子矩阵的和//减去多余部分
}

return 0;
}



scanf / printf 750ms
cin / cout 3000ms
cin / cout + ios::sync_with_stdio(0); 1500ms

wmh123
2天前


#include <iostream>
//#include <cstdio>

using namespace std;

const int N = 1010;

int n, m, q;
int s[N][N];//二维数组

int main()
{
ios::sync_with_stdio(0);
cin >> n >> m >> q;

for (int i = 1; i <= n; i ++ ) //输入矩阵
{
for (int j = 1; j <= m; j ++ )
{
cin >> s[i][j];
}

}

for (int i = 1; i <= n; i ++ )//求和后矩阵
{
for (int j = 1; j <= m; j ++ )
{
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
//二维前缀和预处理公式
}
}

while (q -- )
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] << endl;
//以(x1, y1)为左上角，(x2, y2)为右下角的子矩阵的和//减去多余部分
}

return 0;
}



scanf / printf 750ms
cin / cout 3000ms
cin / cout + ios::sync_with_stdio(0); 1500ms

wmh123
2天前
#include <iostream>
#include <vector>//容器
#include <algorithm>//stl容器算法

using namespace std;

vector<int> div(vector<int> &A, int b, int &r)//r传入r的地址，便于直接对余数r进行修改
{
vector<int> C;
r = 0;//余数
for (int i = A.size() - 1; i >= 0; i -- )//从高位到低位
{
r = r * 10 + A[i];//除以下一位时的余数要放大10倍如72 / 21 = 03 ··· 9
C.push_back(r / b);
r %= b;
}
reverse(C.begin(), C.end());//对数组C进行反转
//做除法时是正向的，0在vector<int> C 的尾部， 反转后可以去除前导0，输出时再反向输出
while (C.size() > 1 && C.back() == 0) C.pop_back();//去前导0

return C;

}

int main()
{
string a;//被除数
vector<int> A;

int b;//除数
cin >> a >> b;
for (int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - '0');

int r;//余数
auto C = div(A, b, r);

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];

cout << endl << r << endl;

return 0;
}



wmh123
2天前
#include <iostream>
#include <vector>//容器
#include <algorithm>//stl容器算法

using namespace std;

vector<int> div(vector<int> &A, int b, int &r)//r传入r的地址，便于直接对余数r进行修改
{
vector<int> C;
r = 0;//余数
for (int i = A.size() - 1; i >= 0; i -- )//从高位到低位
{
r = r * 10 + A[i];//除以下一位时的余数要放大10倍如72 / 21 = 03 ··· 9
C.push_back(r / b);
r %= b;
}
reverse(C.begin(), C.end());//对数组C进行反转
//做除法时是正向的，0在vector<int> C 的尾部， 反转后可以去除前导0，输出时再反向输出
while (C.size() > 1 && C.back() == 0) C.pop_back();//去前导0

return C;

}

int main()
{
string a;//被除数
vector<int> A;

int b;//除数
cin >> a >> b;
for (int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - '0');

int r;//余数
auto C = div(A, b, r);

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];

cout << endl << r << endl;

return 0;
}



wmh123
2天前
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

vector<int> mul(vector<int> &A, int b/*b小*/)//multiply乘
{
vector<int> C;
//1 ≤ A的长度 ≤ 100000/*0 <= A <= 999999*/, 0 ≤ B ≤ 10000
int t = 0;//进位
for (int i = 0; i < A.size() /*|| t != 0*//*防止超位的数未加*/; i ++ )
{
/*if (i < A.size())*/ t += A[i] * b;
C.push_back(t % 10);
t /= 10;//进的位数
}
/**/if(t) C.push_back(t);//最高位进位

while (C.size() > 1 && C.back() == 0) C.pop_back();//去除前导0

return C;
}

int main()
{
string a;
int b;//b 比较小

cin >> a >> b;

vector<int> A;

for (int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - 48);//'0' = 48

//vector<int> C = mul(A, b);
auto C = mul(A, b);

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];

return 0;
}


wmh123
2天前
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

vector<int> mul(vector<int> &A, int b/*b小*/)//multiply乘
{
vector<int> C;
//1 ≤ A的长度 ≤ 100000/*0 <= A <= 999999*/, 0 ≤ B ≤ 10000
int t = 0;//进位
for (int i = 0; i < A.size() /*|| t != 0*//*防止超位的数未加*/; i ++ )
{
/*if (i < A.size())*/ t += A[i] * b;
C.push_back(t % 10);
t /= 10;//进的位数
}
/**/if(t) C.push_back(t);//最高位进位

while (C.size() > 1 && C.back() == 0) C.pop_back();//去除前导0

return C;
}

int main()
{
string a;
int b;//b 比较小

cin >> a >> b;

vector<int> A;

for (int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - 48);//'0' = 48

//vector<int> C = mul(A, b);
auto C = mul(A, b);

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];

return 0;
}


wmh123
9天前

#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int n, m;
int a[N], s[N];

int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> a[i];

for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + a[i]; // 前缀和的初始化

while (m -- )
{
int l, r;
cin >> l >> r;
cout << s[r] - s[l - 1] << endl; // 区间和的计算
}

return 0;
}


1000ms

wmh123
9天前

#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int n, m;
int a[N], s[N];

int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> a[i];

for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + a[i]; // 前缀和的初始化

while (m -- )
{
int l, r;
cin >> l >> r;
cout << s[r] - s[l - 1] << endl; // 区间和的计算
}

return 0;
}


1000ms

wmh123
9天前
#include <iostream>
#include <vector>

using namespace std;

bool cmp(vector<int>& A, vector<int> &B)//比较
{
if(A.size() != B.size()) return A.size() > B.size();  //直接return 了就不用else

for(int i = A.size() - 1; i >= 0; i--)
//严谨来说，是i = A.size() - 1，不过这里A.size()的那一位等于0，
//所以都相等，不影响最终结果
if(A[i] != B[i]) return A[i] > B[i];

return true;//对于A和B相等的情况，避免输出负号
//对于有要有返回值的函数，一定要确定有返回值，不能有无返回值的情况，
//比如说return在if当中的话，return就有概率无法执行，一定要有一个return true
}

vector <int> sub(vector<int>& A, vector<int> &B)//subtraction减法
{
vector<int> C;
int t = 0;//借位
for(int i = 0; i < A.size(); i ++)
{
t = A[i] - t;//读入A[i]
if (i < B.size()) t -= B[i];//A[i] - B[i]
C.push_back((t + 10) % 10 ); // 两步运算合二为一
if (t < 0)  t = 1;//判断正负
else t = 0;
}

while (C.size() > 1 && C.back() == 0) C.pop_back();  //去掉前导0(对齐)

return C;
}

int main()
{
string a ,b;
vector<int> A, B;

cin >> a >> b ;

for(int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0');
for(int i = b.size() - 1; i >= 0; i--) B.push_back(b[i] - 48);
//
vector<int> C;

if (cmp(A, B)) C = sub(A, B);
else C = sub(B, A), cout << '-';

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];
cout << endl;
/*
if (cmp(A,B))
{
auto C = sub(A, B);
for(int i = C.size() - 1; i >= 0; i--) printf("%d", C[i]);
//return 0;
}
else
{
auto C = sub(B, A);
printf("-");
for(int i = C.size() - 1; i >= 0; i--) printf("%d", C[i]);
//return 0;
}
*/
return 0;
}



wmh123
9天前
#include <iostream>
#include <vector>

using namespace std;

bool cmp(vector<int>& A, vector<int> &B)//比较
{
if(A.size() != B.size()) return A.size() > B.size();  //直接return 了就不用else

for(int i = A.size() - 1; i >= 0; i--)
//严谨来说，是i = A.size() - 1，不过这里A.size()的那一位等于0，
//所以都相等，不影响最终结果
if(A[i] != B[i]) return A[i] > B[i];

return true;//对于A和B相等的情况，避免输出负号
//对于有要有返回值的函数，一定要确定有返回值，不能有无返回值的情况，
//比如说return在if当中的话，return就有概率无法执行，一定要有一个return true
}

vector <int> sub(vector<int>& A, vector<int> &B)//subtraction减法
{
vector<int> C;
int t = 0;//借位
for(int i = 0; i < A.size(); i ++)
{
t = A[i] - t;//读入A[i]
if (i < B.size()) t -= B[i];//A[i] - B[i]
C.push_back((t + 10) % 10 ); // 两步运算合二为一
if (t < 0)  t = 1;//判断正负
else t = 0;
}

while (C.size() > 1 && C.back() == 0) C.pop_back();  //去掉前导0(对齐)

return C;
}

int main()
{
string a ,b;
vector<int> A, B;

cin >> a >> b ;

for(int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0');
for(int i = b.size() - 1; i >= 0; i--) B.push_back(b[i] - 48);
//
vector<int> C;

if (cmp(A, B)) C = sub(A, B);
else C = sub(B, A), cout << '-';

for (int i = C.size() - 1; i >= 0; i -- ) cout << C[i];
cout << endl;
/*
if (cmp(A,B))
{
auto C = sub(A, B);
for(int i = C.size() - 1; i >= 0; i--) printf("%d", C[i]);
//return 0;
}
else
{
auto C = sub(B, A);
printf("-");
for(int i = C.size() - 1; i >= 0; i--) printf("%d", C[i]);
//return 0;
}
*/
return 0;
}