提交 80e70db5 编写于 作者: 每日一练社区's avatar 每日一练社区

add 18 exercises

上级 4b72dac3
......@@ -17,3 +17,4 @@ test.html
leetcode_class.md
fix_bug.py
tools.py
lanqiao.cpp
\ No newline at end of file
......@@ -4,15 +4,7 @@
一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”
请你推算一下,他当时到底有多年轻。
## aop
### before
```cpp
```
### after
以下代码的输出中包含了该数学家的真实年龄,请你从下面四个选项中选择正确答案。
```cpp
#include <iostream>
......@@ -30,6 +22,20 @@ int main()
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
......
......@@ -5,32 +5,12 @@
![](https://img-blog.csdn.net/20160125091111485)
上图表示了分块乘法的原理。可以把大数分成多段(此处为2段)小数,然后用小数的多次运算组合表示一个大数。可以根据int的承载能力规定小块的大小,比如要把int分成2段,则小块可取10000为上限值。注意,小块在进行纵向累加后,需要进行进位校正。
## aop
### before
```cpp
#include <stdio.h>
```
### after
请从以下四个选项中选择正确答案,填补在空白处,使得代码能运行后能产生正确的结果。
```cpp
int main(int argc, char *argv[])
{
int x[] = {0, 0, 0, 0};
#include <bits/stdc++.h>
using namespace std;
bigmul(87654321, 12345678, x);
printf("%d%d%d%d\n", x[0], x[1], x[2], x[3]);
return 0;
}
```
## 答案
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
......@@ -46,7 +26,7 @@ void bigmul(int x, int y, int r[])
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 % base;
r[1] = __________________;
r[0] = n4 / base;
r[1] += r[2] / base;
......@@ -54,90 +34,54 @@ void bigmul(int x, int y, int r[])
r[0] += r[1] / base;
r[1] = r[1] % base;
}
int main(int argc, char *argv[])
{
int x[] = {0, 0, 0, 0};
bigmul(87654321, 12345678, x);
printf("%d%d%d%d\n", x[0], x[1], x[2], x[3]);
return 0;
}
```
## 选项
## aop
### A
### before
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
```
### after
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 % base;
r[0] = n4 / base;
```cpp
r[1] += r[2] % base;
r[2] = r[2] / base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```
### B
## 答案
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
n2 / base + n3 / base + n4 % base
```
## 选项
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 / base;
r[0] = n4 / base;
### A
r[1] += r[2] / base;
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```cpp
n2 % base + n3 / base + n4 / base
```
### C
### B
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
n2 / base + n3 % base + n4 / base
```
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 % base + n4 / base;
r[0] = n4 / base;
### C
r[1] += r[2] / base;
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```cpp
n2 / base + n3 / base + n4 / base
```
......@@ -14,6 +14,8 @@
1. 总数目包含题目给出的那个示例。
2. 乘数和被乘数交换后作为同一方案来看待。
以下错误的是?
## aop
### before
......@@ -21,8 +23,6 @@
```cpp
#include <bits/stdc++.h>
using namespace std;
int bei[10];
map<long long, int> mp;
```
### after
......@@ -33,11 +33,14 @@ map<long long, int> mp;
## 答案
```cpp
int bei[10];
map<long long, int> mp;
int main()
{
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int res = 0;
do
while (next_permutation(a, a + 9))
{
for (int i = 1; i < 9; i++)
{
......@@ -52,7 +55,6 @@ int main()
for (int k = i + 1; k < 9; k++)
{
right = right * 10 + a[k];
x = x * 10 + a[k];
}
y = right;
y = y * 10;
......@@ -61,7 +63,7 @@ int main()
ans = left * right;
long long int ff = ans;
while (ans > 0)
while (ans >= 0)
{
int x = ans % 10;
ans = ans / 10;
......@@ -71,14 +73,14 @@ int main()
t++;
}
}
if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0)
if (mp.count(x) == 0 && mp.count(y) == 0)
{
res++;
mp[x] = 1;
mp[y] = 1;
}
}
} while (next_permutation(a, a + 9));
};
cout << res << endl;
return 0;
}
......@@ -89,52 +91,55 @@ int main()
### A
```cpp
int main()
const int N = 1e3 + 5;
int a[15] = {9, 2, 1, 3, 8, 5, 6, 7, 4}, res = 0, vis[12], temp1;
bool fun(int x)
{
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int res = 0;
while (next_permutation(a, a + 9))
int t1 = 0, t2 = 0;
for (int i = x, j = 1; i >= 0; i--, j *= 10)
{
for (int i = 1; i < 9; i++)
t1 = a[i] * j + t1;
}
for (int i = 8, j = 1; i > x; i--, j *= 10)
{
memset(bei, 0, sizeof(bei));
long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0;
for (int j = 0; j <= i; j++)
t2 = a[i] * j + t2;
}
temp1 = t1 * t2;
int temp = temp1;
memset(vis, 0, sizeof(vis));
while (temp)
{
left = left * 10 + a[j];
vis[temp % 10] = 1;
temp /= 10;
}
x = left;
x = x * 10;
for (int k = i + 1; k < 9; k++)
for (int i = 1; i <= 9; i++)
{
right = right * 10 + a[k];
if (!vis[i])
return false;
}
y = right;
y = y * 10;
for (int j = 0; j <= i; j++)
y = y * 10 + a[j];
return true;
}
int main()
{
ans = left * right;
long long int ff = ans;
while (ans >= 0)
for (int i = 0; i < 9; i++)
a[i] = i + 1;
set<int> st;
do
{
int x = ans % 10;
ans = ans / 10;
if (bei[x] == 0 && x != 0)
for (int i = 0; i < 8; i++)
{
bei[x] = 1;
t++;
}
}
if (mp.count(x) == 0 && mp.count(y) == 0)
if (fun(i))
{
st.insert(temp1);
res++;
mp[x] = 1;
mp[y] = 1;
}
}
};
cout << res << endl;
} while (next_permutation(a, a + 9));
cout << res / 2 << '\n';
return 0;
}
```
......@@ -142,52 +147,66 @@ int main()
### B
```cpp
int main()
int st[10], res[10], book[10], cnt;
int cal(int l, int r)
{
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int res = 0;
do
int t = 0;
for (int i = l; i <= r; i++)
{
for (int i = 1; i < 9; i++)
{
memset(bei, 0, sizeof(bei));
long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0;
for (int j = 0; j <= i; j++)
t = t * 10 + res[i];
}
return t;
}
bool check(int k)
{
for (int i = 0; i < 10; i++)
book[i] = 0;
while (k)
{
left = left * 10 + a[j];
book[k % 10]++;
k /= 10;
}
x = left;
x = x * 10;
for (int k = i + 1; k < 9; k++)
bool flag = true;
for (int i = 1; i <= 9; i++)
{
right = right * 10 + a[k];
x = x * 10 + a[k];
if (book[i] != 1)
flag = false;
}
y = right;
y = y * 10;
for (int j = 0; j <= i; j++)
y = y * 10 + a[j];
return flag;
}
long long int ff = ans;
while (ans > 0)
void dfs(int k)
{
if (k == 9)
{
int x = ans % 10;
ans = ans / 10;
if (bei[x] == 0 && x != 0)
for (int i = 0; i < 8; i++)
{
bei[x] = 1;
t++;
int a = cal(0, i);
int b = cal(i + 1, 8);
if (check(a * b))
{
cnt++;
}
}
return;
}
if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0)
for (int i = 1; i <= 9; i++)
{
res++;
mp[x] = 1;
mp[y] = 1;
if (!st[i])
{
st[i] = 1;
res[k] = i;
dfs(k + 1);
st[i] = 0;
}
}
} while (next_permutation(a, a + 9));
cout << res << endl;
}
int main()
{
dfs(0);
cout << cnt / 2;
return 0;
}
```
......@@ -195,52 +214,87 @@ int main()
### C
```cpp
int main()
typedef long long LL;
const int N = 15;
bool vis[N];
int ans;
bool check_2(LL sumb)
{
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int res = 0;
while (next_permutation(a, a + 9))
bool st[N];
for (int i = 1; i <= 9; i++)
{
for (int i = 1; i < 9; i++)
st[i] = 0;
}
while (sumb)
{
memset(bei, 0, sizeof(bei));
long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0;
for (int j = 0; j <= i; j++)
st[sumb % 10] = true;
sumb = sumb / 10;
}
bool flag = false;
for (int i = 1; i <= 9; i++)
{
left = left * 10 + a[j];
if (!st[i])
{
return false;
}
x = left;
x = x * 10;
for (int k = i + 1; k < 9; k++)
}
return true;
}
bool check_1(int suma, int sumc)
{
LL sumb = (LL)suma * sumc;
if (check_2(sumb))
{
right = right * 10 + a[k];
return true;
}
y = right;
y = y * 10;
for (int j = 0; j <= i; j++)
y = y * 10 + a[j];
return false;
}
ans = left * right;
long long int ff = ans;
while (ans > 0)
void dfs_c(int u, int suma, int sumc)
{
if (u > 9)
{
int x = ans % 10;
ans = ans / 10;
if (bei[x] == 0 && x != 0)
return;
}
if (check_1(suma, sumc))
{
bei[x] = 1;
t++;
ans++;
return;
}
for (int i = 1; i <= 9; i++)
{
if (!vis[i])
{
vis[i] = true;
dfs_c(u + 1, suma, sumc * 10 + i);
vis[i] = false;
}
if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0)
}
}
void dfs_a(int u, int suma)
{
dfs_c(u, suma, 0);
for (int i = 1; i <= 9; i++)
{
res++;
mp[x] = 1;
mp[y] = 1;
if (!vis[i])
{
vis[i] = true;
dfs_a(u + 1, suma * 10 + i);
vis[i] = false;
}
}
};
cout << res << endl;
}
int main()
{
dfs_a(0, 0);
cout << ans / 2 << endl;
return 0;
}
```
......@@ -15,47 +15,27 @@
例如,有一种可能是:```20,5,4,2,0```
以下错误的一项是?
## aop
### before
```cpp
#include <cstdio>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int d, a1[4];
```
### after
```cpp
int main()
{
for (int sum = 20; sum >= 1; sum--)
{
for (int a = 1; a <= 20; a++)
{
for (int b = 1; b <= 20; b++)
{
for (int c = 1; c <= 20; c++)
{
a1[0] = sum, a1[1] = a, a1[2] = b, a1[3] = c;
if (getS(a1) == a1[0] && a > b && b > c && sum > a)
{
printf("%d, %d, %d, %d, 0\n", sum, a, b, c);
}
}
}
}
}
return 0;
}
```
## 答案
```cpp
int d, a1[4];
int d1(int *a1)
{
int sum = a1[0];
......@@ -74,12 +54,31 @@ int getS(int *a1)
int index = d1(a1);
a1[0] = a1[0] * a1[index];
ss = a1[index];
sum += ss;
}
for (int i = 1; i < 4; i++)
return sum;
}
int main()
{
for (int sum = 20; sum >= 1; sum--)
{
for (int a = 1; a <= 20; a++)
{
for (int b = 1; b <= 20; b++)
{
sum += (a1[0] / a1[i]);
for (int c = 1; c <= 20; c++)
{
a1[0] = sum, a1[1] = a, a1[2] = b, a1[3] = c;
if (getS(a1) == a1[0] && a > b && b > c && sum > a)
{
printf("%d, %d, %d, %d, 0\n", sum, a, b, c);
}
}
}
return sum + ss;
}
}
return 0;
}
```
## 选项
......@@ -88,86 +87,99 @@ int getS(int *a1)
### A
```cpp
int d1(int *a1)
int main()
{
int sum = a1[0];
for (int i = 1; i < 4; i++)
float n;
float a, b, c;
float s1, s2, s3;
for (n = 5; n <= 20; n++)
{
if (sum % a1[i] != 0)
return i;
}
return 0;
}
int getS(int *a1)
{
int sum = 0, ss = 1;
while (d1(a1) != 0)
for (a = 1; a <= n; a++)
for (b = 1; b <= n; b++)
for (c = 1; c <= n; c++)
{
int index = d1(a1);
a1[0] = a1[0] * a1[index];
ss = a1[index];
s1 = n - a;
s2 = n - a - b;
s3 = n - a - b - c;
if (1 / n + 1 / s1 + 1 / s2 + 1 / s3 == 1 && s1 > 0 && s2 > 0 && s3 > 0)
cout << n << "," << s1 << "," << s2 << "," << s3 << ","
<< "0" << endl;
}
for (int i = 1; i <= 4; i++)
{
sum += (a1[0] / a1[i]);
}
return sum + ss;
return 0;
}
```
### B
```cpp
int d1(int *a1)
int cm(int a, int b)
{
int sum = a1[0];
for (int i = 1; i <= 4; i++)
int temp;
int mul;
mul = a * b;
if (a % b == 0)
return a;
else
{
if (sum % a1[i] != 0)
return i;
while (a % b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return mul * b;
}
return 0;
}
int getS(int *a1)
int main()
{
int sum = 0, ss = 1;
while (d1(a1) != 0)
{
int index = d1(a1);
a1[0] = a1[0] * a1[index];
ss = a1[index];
int a, b, c, d;
int temp;
int ta, tb, tc, td;
for (a = 20; a >= 5; a--)
for (b = a - 1; b >= 4; b--)
for (c = b - 1; c >= 3; c--)
for (d = c - 1; d >= 2; d--)
{
temp = cm(a, b);
temp = cm(temp, c);
temp = cm(temp, d);
ta = temp / a;
tb = temp / b;
tc = temp / c;
td = temp / d;
if (ta + tb + tc + td == temp)
cout << a << "," << b << "," << c << "," << d << ","
<< "0" << endl;
}
for (int i = 1; i <= 4; i++)
{
sum += (a1[0] / a1[i]);
}
return sum + ss;
return 0;
}
```
### C
```cpp
int d1(int *a1)
int main(void)
{
int sum = a1[0];
for (int i = 1; i < 4; i++)
float a, b, c, d;
float x, y, z, m;
for (x = 20; x >= 5; x--)
{
if (sum % a1[i] != 0)
return i;
}
return 0;
}
int getS(int *a1)
{
int sum = 0, ss = 1;
while (d1(a1) != 0)
for (y = x - 1; y >= 4; y--)
{
int index = d1(a1);
a1[0] = a1[0] * a1[index];
ss = a1[index];
sum += ss;
for (z = y - 1; z >= 3; z--)
{
for (m = y - 1; m >= 2; m--)
{
if (y * z * m + x * z * m + x * y * m + x * y * z == x * y * z * m)
{
cout << x << "," << y << "," << z << "," << m << ","
<< "0" << endl;
}
}
}
}
}
return sum;
}
```
......@@ -4,6 +4,7 @@
类似:3/2
当然,这只是加了前2项而已。分子分母要求互质。
下面哪一项是错误的?
## aop
### before
......@@ -15,17 +16,7 @@ using namespace std;
### after
```cpp
int gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
cout << gcd(pow_2(20) - 1, pow_2(19)) << endl;
cout << pow_2(20) - 1 << "/" << pow_2(19) << endl;
}
```
## 答案
......@@ -44,6 +35,17 @@ long pow_2(int b)
}
return res;
}
int gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
cout << pow_2(20) << "/" << pow_2(19) << endl;
}
```
## 选项
......@@ -59,45 +61,63 @@ long pow_2(int b)
{
if (b & 1)
res *= x;
b <<= 1;
b >>= 1;
x = x * x;
}
return res;
}
int gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
cout << pow_2(20) - 1 << "/" << pow_2(19) << endl;
}
```
### B
```cpp
long pow_2(int b)
int gcd(int a, int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b && 1)
res *= x;
b <<= 1;
x = x * x;
}
return res;
return a % b ? gcd(b, a % b) : b;
}
int main()
{
int a = 1048575, b = 524288;
int t = gcd(a, b);
cout << a / t << "/" << b / t << endl;
return 0;
}
```
### C
```cpp
long pow_2(int b)
int gcd(int a, int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b & 1)
res = x;
b >>= 1;
x = x * x;
int c;
c = a % b;
a = b;
b = c;
}
return res;
return a;
}
int main()
{
int a = 1048575;
int b = 524288;
int c = gcd(a, b);
cout << a / c << "/" << b / c << endl;
return 0;
}
```
......@@ -43,14 +43,14 @@
71.29
```
以下选项错误的是?
## aop
### before
```cpp
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
```
### after
......@@ -66,24 +66,22 @@ int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
int maxv = 0, minv = 100, sum = 0;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
top = score;
if (score < low)
low = score;
sum += score;
int x;
cin >> x;
minv = min(minv, x);
maxv = max(maxv, x);
sum += x;
}
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
cout << maxv << endl;
cout << minv << endl;
printf("%.2f", sum / n);
return 0;
}
```
## 选项
......@@ -93,23 +91,32 @@ int main()
```cpp
int main()
{
int n;
int n, max = 0, min = 0;
double sum = 0, average = 0;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
int a[10000];
cin >> a[0];
sum = a[0];
max = a[0];
min = a[0];
for (int i = 1; i < n; i++)
{
cin >> score;
if (score > top)
top = score;
if (score < low)
low = score;
sum += score;
cin >> a[i];
if (max < a[i])
{
max = a[i];
}
if (min > a[i])
{
min = a[i];
}
sum += a[i];
}
printf("%d\n%d\n%.f", top, low, (sum * 1.0 / n));
average = sum / n;
cout << max << endl
<< min << endl
<< setiosflags(ios::fixed) << setprecision(2) << average;
return 0;
}
```
......@@ -117,25 +124,56 @@ int main()
### B
```cpp
int n;
int Max(int m[10005])
{
int max = m[0];
for (int i = 1; i < n; i++)
{
if (max < m[i])
{
max = m[i];
}
}
return max;
}
int Min(int m[10005])
{
int min = m[0];
for (int i = 1; i < n; i++)
{
if (min > m[i])
{
min = m[i];
}
}
return min;
}
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int m[10005];
for (int i = 0; i < n; i++)
{
cin >> m[i];
}
int ans = 0;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
score = top;
if (score < low)
score = low;
sum += score;
ans += m[i];
}
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
int a = Max(m);
int b = Min(m);
cout << "最高分 = " << a << endl;
cout << "最低分 = " << b << endl;
printf("%.2lf", 1.0 * ans / n);
return 0;
}
```
......@@ -155,13 +193,13 @@ int main()
for (int i = 0; i < n; i++)
{
cin >> score;
if (score < top)
if (score > top)
top = score;
if (score > low)
if (score < low)
low = score;
sum += score;
}
printf("%d\n%d\n%d", top, low, (sum / n));
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
return 0;
}
```
......@@ -12,17 +12,14 @@ x星的国王有个怪癖,他只喜欢数字3,5和7。
请你帮小明计算一下,59084709587505是第几个幸运数字。
以下选项错误的是?
## aop
### before
```cpp
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <bits/stdc++.h>
using namespace std;
```
### after
......@@ -34,34 +31,27 @@ using namespace std;
## 答案
```cpp
typedef long long LL;
const LL MAX = 59084709587505;
int main()
{
set<long long> st;
priority_queue<long long, vector<long long>, greater<long long>> pq;
const int ok[3] = {3, 5, 7};
st.insert(1);
pq.push(1);
int times = 0;
int a[3] = {3, 5, 7};
LL tou = 1;
set<LL> s;
while (true)
{
long long lucky = pq.top();
pq.pop();
if (lucky == 59084709587505)
{ //49
cout << times << endl;
return 0;
}
times++;
for (int i = 0; i < 3; i++)
{
long long b = lucky * ok[i];
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
LL tt = tou * a[i];
if (tt <= MAX)
s.insert(tt);
}
tou = s.upper_bound(tou);
if (tou >= MAX)
break;
}
cout << s.size() << endl;
return 0;
}
```
......@@ -71,34 +61,32 @@ int main()
### A
```cpp
#define LL long long
LL maxs = 59084709587505;
set<LL> q;
int main()
{
set<long long> st;
priority_queue<long long, vector<long long>, greater<long long>> pq;
const int ok[3] = {3, 5, 7};
st.insert(1);
pq.push(1);
int times = 0;
while (true)
{
long long lucky = pq.top();
pq.pop();
if (lucky == 59084709587505)
{ //49
cout << times << endl;
return 0;
}
times++;
for (int i = 0; i < 3; i++)
q.insert(3);
q.insert(5);
q.insert(7);
set<LL>::iterator it;
it = q.begin();
LL mid;
while (*it <= maxs)
{
long long b = lucky * ok[i + 1];
if (!st.count(b))
mid = *it;
q.insert(mid * 3);
q.insert(mid * 5);
q.insert(mid * 7);
it++;
}
int num = 0;
for (it = q.begin(); it != q.end(); it++)
{
st.insert(b);
pq.push(b);
}
}
if (*it <= maxs)
num++;
}
cout << num;
return 0;
}
```
......@@ -106,37 +94,35 @@ int main()
### B
```cpp
int main()
typedef long long LL;
const LL Max = 59084709587505;
int a[3] = {3, 5, 7};
void Find(LL Max)
{
set<long long> st;
priority_queue<long long, vector<long long>, greater<long long>> pq;
const int ok[3] = {3, 5, 7};
st.insert(1);
pq.push(1);
int times = 0;
while (true)
{
long long lucky = pq.top();
pq.pop();
if (lucky == 59084709587505)
{ //49
cout << times << endl;
return 0;
}
times++;
for (int i = 0; i < 3; i++)
set<LL> se;
LL t = 1;
while (1)
{
long long b = lucky * ok[i] + 1;
if (!st.count(b))
for (int i = 0; i < 3; ++i)
{
st.insert(b);
pq.push(b);
LL tt = t * a[i];
if (tt <= Max)
se.insert(tt);
}
t = *se.upper_bound(t);
if (t == Max)
break;
}
}
return 0;
cout << se.size() << endl;
}
int main(void)
{
Find(Max);
return 0;
}
```
### C
......@@ -155,14 +141,14 @@ int main()
long long lucky = pq.top();
pq.pop();
if (lucky == 59084709587505)
{ //49
{
cout << times << endl;
return 0;
}
times++;
for (int i = 0; i < 3; i++)
{
long long b = lucky + ok[i];
long long b = lucky * ok[i];
if (!st.count(b))
{
st.insert(b);
......@@ -172,5 +158,4 @@ int main()
}
return 0;
}
```
......@@ -12,84 +12,60 @@
长度为10的等差素数列,其公差最小值是多少?
以下选项错误的是?
## aop
### before
```cpp
#include <cstdio>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
```
### after
typedef long long LL;
set<int> all;
```cpp
bool isPrimt(LL t)
{
for (int i = 2; i < t / 2; ++i)
{
if (t % i == 0)
return false;
}
return true;
}
```
### after
## 答案
```cpp
const int N = 5000;
int main()
{
LL a[N];
const int N = 10010;
a[0] = 2;
a[1] = 3;
all.insert(2);
all.insert(3);
int k;
int prime[N];
bool st[N], check[N];
int index = 2;
LL t = 5;
while (index < N)
{
if (isPrimt(t))
void init()
{
for (int i = 2; i < N; i++)
if (!st[i])
{
a[index++] = t;
all.insert(t);
}
t++;
prime[k++] = i;
check[i] = true;
for (int j = i + i; j < N; j += i)
st[j] = true;
}
printf("%d\n", f(a, N));
return 0;
}
```
## 答案
```cpp
int f(LL a[], int n)
int main()
{
for (int i = 0; i < n; ++i)
init();
for (int i = 1; i < N; i++)
for (int j = 0; j < k; j++)
{
LL first = a[i];
for (int delta = 1; delta < a[n - 1] - first; ++delta)
int k = prime[j], cnt = 1;
while (check[k + i])
{
int m = first;
for (int j = 1; j < 10; ++j)
k += i;
if (cnt++ == 10)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
cout << i << endl;
return 0;
}
}
}
return -1;
}
```
## 选项
......@@ -98,66 +74,132 @@ int f(LL a[], int n)
### A
```cpp
int f(LL a[], int n)
typedef long long ll;
const ll maxn = 1e6 + 50;
ll a[maxn];
bool ok(ll n, ll cha)
{
for (int i = 0; i < n; ++i)
for (ll i = 0; i < 10; i++)
{
LL first = a[i];
for (int delta = 1; delta < a[n] - first; ++delta)
if (!a[n + i * cha])
return 0;
}
return 1;
}
int main()
{
a[1] = 0;
a[2] = 1;
a[3] = 1;
for (ll i = 4; i <= 1000000; i++)
{
int m = first;
for (int j = 1; j < 10; ++j)
bool flag = 0;
for (ll j = 2; j * j <= i; j++)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
if (i % j == 0)
{
flag = 1;
break;
if (j == 9)
return delta;
}
}
if (flag)
a[i] = 0;
else
a[i] = 1;
}
for (ll cha = 1;; cha++)
{
for (ll i = 2; i < 1000000; i++)
{
if (a[i] && ok(i, cha))
{
printf("%lld\n", cha);
return 0;
}
}
}
return -1;
}
```
### B
```cpp
int f(LL a[], int n)
const int N = 10001;
int prime[N]{0};
int main()
{
for (int i = 0; i < n; ++i)
for (int i = 2; i != N; ++i)
prime[i] = 1;
for (int i = 2; i < N; ++i)
{
LL first = a[i];
for (int delta = 1; delta < a[n + 1] - first; ++delta)
for (int j = i + 1; j < N; ++j)
{
int m = first;
for (int j = 1; j < 10; ++j)
if (j % i == 0)
{
m += delta;
if (all.find(m) == all.end())
if (prime[j] == 1)
prime[j] = 0;
}
}
}
for (int d = 1; d <= 300; ++d)
{
for (int i = 2; i < N; ++i)
{
int a1 = i, flag = 1, len = 1;
while (len < 10)
{
if (prime[a1 + len * d] == 0)
{
flag = 0;
break;
if (m > a[n - 1])
}
else
{
++len;
}
}
if (flag)
{
cout << d << endl;
break;
if (j == 9)
return delta;
}
}
}
return -1;
return 0;
}
```
### C
```cpp
typedef long long LL;
set<int> all;
bool isPrimt(LL t)
{
for (int i = 2; i < t / 2; ++i)
{
if (t % i == 0)
return false;
}
return true;
}
int f(LL a[], int n)
{
for (int i = 0; i < n; ++i)
{
LL first = a[i];
for (int delta = 1; delta < a[n + 1] + first; ++delta)
for (int delta = 1; delta < a[n] - first; ++delta)
{
int m = first;
for (int j = 1; j < 10; ++j)
......@@ -165,8 +207,6 @@ int f(LL a[], int n)
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
}
......@@ -174,4 +214,31 @@ int f(LL a[], int n)
}
return -1;
}
const int N = 5000;
int main()
{
LL a[N];
a[0] = 2;
a[1] = 3;
all.insert(2);
all.insert(3);
int index = 2;
LL t = 5;
while (index < N)
{
if (isPrimt(t))
{
a[index++] = t;
all.insert(t);
}
t++;
}
printf("%d\n", f(a, N));
return 0;
}
```
......@@ -54,14 +54,14 @@
-999999829
```
以下选项错误的是?
## aop
### before
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
```
### after
......@@ -73,43 +73,48 @@ using namespace std;
## 答案
```cpp
#define ll long long
#define inf 0x7fffffff
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 9;
int n, k;
int a[N];
ll ans = 1;
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int sign = 1;
if (k % 2)
{
ans = num.back();
k = k - 1;
num.pop_back();
ans = a[n];
n--;
k--;
}
else
ans = 1;
while (k > 0)
int i = 0, j = n;
while (k)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2))
ll tmp1 = (ll)a[i] * a[i + 1], tmp2 = (ll)a[j] * a[j - 1];
if (tmp1 * sign > tmp2 * sign)
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
ans = (tmp1 % mod * ans) % mod;
i += 2;
}
else
{
ans = ans * num.at(num.size() - 1) * num.at(num.size() - 2) % 1000000009;
num.pop_back();
num.pop_back();
ans = (tmp2 % mod * ans) % mod;
j -= 2;
}
k -= 2;
}
cout << ans;
printf("%lld\n", ans);
return 0;
}
......@@ -120,43 +125,164 @@ int main()
### A
```cpp
#define mem(a, b) memset(a, b, sizeof(a))
#define mod 1000000009
typedef long long ll;
const int maxn = 1e6 + 5;
const double esp = 1e-7;
const int ff = 0x3f3f3f3f;
map<int, int>::iterator it;
struct node
{
ll x;
int f;
} a[maxn];
int n, k;
bool cmp(node x, node y)
{
return x.x > y.x;
}
ll solve(int o)
{
ll ans = 1;
int cnt = 0;
if (o == 0)
{
for (int i = 1; i <= k; i++)
{
ans = (ans * a[i].x) % mod;
if (a[i].f == 1)
cnt++;
}
}
else
{
for (int i = n; i > n - k; i--)
{
ans = (ans * a[i].x) % mod;
if (a[i].f == 1)
cnt++;
}
}
if (cnt & 1)
return ans * (-1);
return ans;
}
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
int flag = 0;
int cnt = 0;
for (int i = 1; i <= n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
scanf("%lld", &a[i].x);
if (a[i].x < 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
a[i].f = 1;
a[i].x = -a[i].x;
cnt++;
}
else if (a[i].x > 0)
a[i].f = 0;
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size()) * num.at(num.size() - 1))
i--;
n--;
flag = 1;
}
}
sort(a + 1, a + n + 1, cmp);
ll ans = 0;
if (n < k)
ans = 0;
else if (cnt == n)
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
if (k & 1)
ans = solve(1);
else
ans = solve(0);
}
else if (cnt == 0)
ans = solve(0);
else
{
ans = ans * num.at(num.size()) * num.at(num.size() - 1) % 1000000009;
num.pop_back();
num.pop_back();
int tmp = 0;
for (int i = 1; i <= k; i++)
if (a[i].f == 1)
tmp++;
if (tmp % 2 == 0)
ans = solve(0);
else
{
ans = -1;
int p = -1, q = -1;
for (int i = k + 1; i <= n; i++)
if (a[i].f == 0)
{
q = i;
break;
}
k -= 2;
for (int i = k; i >= 1; i--)
if (a[i].f == 1)
{
p = i;
break;
}
cout << ans;
if (p != -1 && q != -1)
{
swap(a[p], a[q]);
ans = solve(0);
swap(a[p], a[q]);
}
p = -1, q = -1;
for (int i = k + 1; i <= n; i++)
if (a[i].f == 1)
{
q = i;
break;
}
for (int i = k; i >= 1; i--)
if (a[i].f == 0)
{
p = i;
break;
}
if (p != -1 && q != -1)
{
swap(a[p], a[q]);
ans = max(ans, solve(0));
swap(a[p], a[q]);
}
if (ans < 0)
ans = solve(1);
}
}
if (ans < 0)
if (flag)
{
cout << 0 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
```
......@@ -164,43 +290,72 @@ int main()
### B
```cpp
#define mod 1000000009
const int N = 100010;
typedef long long LL;
int a[N];
int n, k;
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
scanf("%d", &a[i]);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
sort(a, a + n);
LL res = 1;
if (n == k)
{
ans = num.back();
k = k - 1;
num.pop_back();
for (int i = 0; i < n; i++)
{
res = (res * a[i]) % mod;
}
cout << res % mod;
return 0;
}
if (a[n - 1] < 0)
{
if (k % 2 == 1)
{
for (int i = n - 1; i >= n - k; i--)
{
res = (res * a[i]) % mod;
}
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 1))
for (int i = 0; i < k; i++)
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
res = (res * a[i]) % mod;
}
}
cout << res << endl;
return 0;
}
int l = 0, r = n - 1;
if (k % 2 == 1)
{
res = a[r--];
k--;
}
while (k)
{
LL x = (LL)a[l] * a[l + 1], y = (LL)a[r] * a[r - 1];
if (x > y)
{
res = x % mod * res % mod;
l += 2;
}
else
{
ans = ans * num.at(num.size() - 1) % 1000000009;
num.pop_back();
num.pop_back();
res = y % mod * res % mod;
r -= 2;
}
k -= 2;
}
cout << ans;
cout << res << endl;
return 0;
}
```
......@@ -238,7 +393,7 @@ int main()
}
else
{
ans = ans * num.at(num.size() - 1) % 1000000009;
ans = ans * num.at(num.size() - 1) * num.at(num.size() - 2) % 1000000009;
num.pop_back();
num.pop_back();
}
......
......@@ -14,12 +14,14 @@
689 5510 8243 6114 337 4096 8199 7313 3685 211
```
以下错误的选项是?
## aop
### before
```cpp
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
```
### after
......@@ -41,12 +43,12 @@ int main()
while (num % 5 == 0)
{
count5++;
num /= 5;
num %= 5;
}
while (num % 2 == 0)
{
count2++;
num /= 2;
num %= 2;
}
}
int ans = count2 < count5 ? count2 : count5;
......@@ -62,24 +64,20 @@ int main()
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
long long int a, sum = 1, aum = 0;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
cin >> a;
sum = sum * a;
while ((sum % 10) == 0)
{
count5++;
num /= 5;
}
while (num % 2 == 0)
{
count2++;
num /= 2;
sum = sum / 10;
aum++;
}
sum = sum % 10000;
}
int ans = count2 < count5 ? count5 : count2;
cout << ans;
printf("%lld", aum);
return 0;
}
```
......@@ -87,29 +85,30 @@ int main()
### B
```cpp
int a[] = {5650, 4542, 3554, 473, 946, 4114, 3871, 9073, 90, 4329,
2758, 7949, 6113, 5659, 5245, 7432, 3051, 4434, 6704, 3594,
9937, 1173, 6866, 3397, 4759, 7557, 3070, 2287, 1453, 9899,
1486, 5722, 3135, 1170, 4014, 5510, 5120, 729, 2880, 9019,
2049, 698, 4582, 4346, 4427, 646, 9742, 7340, 1230, 7683,
5693, 7015, 6887, 7381, 4172, 4341, 2909, 2027, 7355, 5649,
6701, 6645, 1671, 5978, 2704, 9926, 295, 3125, 3878, 6785,
2066, 4247, 4800, 1578, 6652, 4616, 1113, 6205, 3264, 2915,
3966, 5291, 2904, 1285, 2193, 1428, 2265, 8730, 9436, 7074,
689, 5510, 8243, 6114, 337, 4096, 8199, 7313, 3685, 211};
int main()
{
int count2 = 0, count5 = 0;
int num;
int k1 = 0, k2 = 0;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num %= 5;
}
while (num % 2 == 0)
{
count2++;
num %= 2;
}
while (!(a[i] % 2))
a[i] /= 2, k1++;
while (!(a[i] % 5))
a[i] /= 5, k2++;
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
cout << min(k1, k2);
return 0;
}
```
### C
......@@ -117,24 +116,25 @@ int main()
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
int t_cnt, f_cnt, data = 0;
t_cnt = f_cnt = 0;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
cin >> data;
while (data % 5 == 0)
{
count5++;
num += 5;
f_cnt++;
data /= 5;
}
while (num % 2 == 0)
while (data % 2 == 0)
{
count2++;
num += 2;
t_cnt++;
data /= 2;
}
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
cout << min(t_cnt, f_cnt) << endl;
return 0;
}
```
......@@ -8,12 +8,30 @@
以下的代码打印出了大衍数列的前 100 项。
请填补空白处的内容。
```cpp
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (__________________)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
```
## aop
### before
```cpp
#include <stdio.h>
```
### after
......@@ -24,18 +42,7 @@
## 答案
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
i % 2 == 0
```
## 选项
......@@ -43,50 +50,17 @@ int main()
### A
```cpp
int main()
{
int i;
for (i = 1; i < 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
i % 2 == 1
```
### B
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i / 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
i / 2 == 0
```
### C
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i % 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
i / 2 == 1
```
......@@ -36,12 +36,15 @@ Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
1 <= n <= 1,000,000。
```
下列哪一个选项会超时?
## aop
### before
```cpp
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
```
### after
......@@ -52,22 +55,18 @@ Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
## 答案
```cpp
int main()
int fib(int n)
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i];
}
if (n > 2)
printf("%d", b);
if (n < 3)
return 1;
else
printf("1");
return fib(n - 1) + fib(n - 2);
}
int main()
{
int n;
cin >> n;
cout << fib(n) % 10007 << endl;
return 0;
}
```
......@@ -77,22 +76,28 @@ int main()
### A
```cpp
int main()
int fib(int N)
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
if (N <= 0)
return 0;
if (N == 1 || N == 2)
return 1;
int a = 1, b = 1;
for (int i = 3; i <= N; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i] + 1;
int c = (a + b) % 10007;
a = b;
b = c;
}
if (n > 2)
printf("%d", b);
else
printf("1");
return b;
}
int main()
{
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
```
......@@ -110,7 +115,7 @@ int main()
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i - 1];
b = a[i];
}
if (n > 2)
printf("%d", b);
......@@ -123,22 +128,24 @@ int main()
### C
```cpp
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
int f[1000000 + 1];
for (int i = 2; i < n; i++)
void meter(int n)
{
f[1] = 1;
f[2] = 1;
if (n >= 3)
for (int i = 3; i <= n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i - 2];
f[i] = (f[i - 1] + f[i - 2]) % 10007;
}
if (n > 2)
printf("%d", b);
else
printf("1");
}
int main()
{
meter(1000000);
int n;
cin >> n;
cout << f[n];
return 0;
}
```
......@@ -37,22 +37,15 @@ C = [C1, C2, ... CN],
27
```
以下错误的一项是?
## aop
### before
```cpp
#include <iostream>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int a[N], b[N], c[N], sa[N], sc[N], s[N];
```
### after
......@@ -66,34 +59,47 @@ int a[N], b[N], c[N], sa[N], sc[N], s[N];
int main()
{
int n;
long long ans = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], a[i]++;
for (int i = 0; i < n; i++)
cin >> b[i], b[i]++;
for (int i = 0; i < n; i++)
cin >> c[i], c[i]++;
for (int i = 0; i < n; i++)
s[a[i]]++;
for (int i = 1; i < N; i++)
s[i] += s[i - 1];
for (int i = 0; i < n; i++)
sa[i] = s[b[i] - 1];
memset(s, 0, sizeof s);
for (int i = 0; i < n; i++)
s[c[i]]++;
for (int i = 1; i < N; i++)
s[i] += s[i - 1];
for (int i = 0; i < n; i++)
sc[i] = s[N - 1] - s[b[i]];
LL res = 0;
for (int i = 0; i <= n; i++)
res += (LL)sa[i] * sc[i];
cout << res;
int I[n], J[n], K[n];
for (int i = 0; i < n; i++)
{
cin >> I[i];
}
for (int i = 0; i < n; i++)
{
cin >> J[i];
}
for (int i = 0; i < n; i++)
{
cin >> K[i];
}
sort(I, I + n);
sort(J, J + n);
sort(K, K + n);
int index_min_i = 0, index_min_j = 0;
for (int i = 0; i < n; i++)
{
int count1 = 0, count2 = 0;
for (int j = index_min_i; j < n; j++)
{
if (I[i] < J[j])
{
index_min_i = j;
count1 = n - j;
for (int k = index_min_j; k < n; k++)
{
count2 = n - k;
index_min_j = k;
ans += (long long)(count1 * count2);
}
break;
}
}
}
cout << ans << endl;
return 0;
}
```
## 选项
......@@ -102,80 +108,115 @@ int main()
### A
```cpp
const int maxn = 1e5 + 10;
typedef long long ll;
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
int n;
ll ans = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], a[i]++;
for (int i = 0; i < n; i++)
cin >> b[i], b[i]++;
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> c[i], c[i]++;
cin >> b[i];
for (int i = 0; i < n; i++)
s[a[i]]++;
for (int i = 1; i < N; i++)
s[i] += s[i - 1];
cin >> c[i];
sort(a, a + n);
sort(b, b + n);
sort(c, c + n);
ll cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++)
sa[i] = s[b[i] - 1];
{
while (cnt1 < n && a[cnt1] < b[i])
cnt1++;
while (cnt2 < n && c[cnt2] <= b[i])
cnt2++;
ans += cnt1 * (n - cnt2);
}
memset(s, 0, sizeof s);
for (int i = 0; i < n; i++)
s[c[i]]++;
for (int i = 1; i < N; i++)
s[i] += s[i - 1];
for (int i = 0; i < n; i++)
sc[i] = s[N] - s[b[i]];
LL res = 0;
for (int i = 0; i <= n; i++)
res += (LL)sa[i] * sc[i];
cout << res;
cout << ans << endl;
}
```
### B
```cpp
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], a[i]++;
for (int i = 0; i < n; i++)
cin >> b[i], b[i]++;
for (int i = 0; i < n; i++)
cin >> c[i], c[i]++;
#define ll long long
using namespace std;
for (int i = 0; i < n; i++)
s[a[i]]++;
for (int i = 1; i < N; i++)
s[i] += s[i - 1];
for (int i = 0; i < n; i++)
sa[i] = s[b[i] - 1];
const int N = 100000 + 10;
memset(s, 0, sizeof s);
int a[N], b[N], c[N];
int n;
for (int i = 0; i < n; i++)
s[c[i]]++;
for (int i = 1; i < N; i++)
s[i] = s[i - 1];
for (int i = 0; i < n; i++)
sc[i] = s[N - 1] - s[b[i]];
int find2(int x, int y[])
{
int l = 1, r = n;
while (l < r)
{
int mid = (l + r) >> 1;
if (y[mid] > x)
r = mid;
else
l = mid + 1;
}
if (y[r] <= x)
return 0;
return n - r + 1;
}
LL res = 0;
for (int i = 0; i <= n; i++)
res += (LL)sa[i] * sc[i];
cout << res;
int find1(int x, int y[])
{
int l = 1, r = n;
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (y[mid] < x)
l = mid;
else
r = mid - 1;
}
if (y[l] >= x)
return 0;
return l;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
for (int i = 1; i <= n; i++)
cin >> c[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
sort(c + 1, c + n + 1);
long long ans = 0;
for (int i = 1; i <= n; i++)
{
int x = find1(b[i], a);
int y = find2(b[i], c);
ans += 1ll * x * y;
}
cout << ans;
return 0;
}
```
### C
```cpp
typedef long long LL;
const int N = 1e5 + 10;
int a[N], b[N], c[N], sa[N], sc[N], s[N];
int main()
{
int n;
......@@ -199,9 +240,9 @@ int main()
for (int i = 0; i < n; i++)
s[c[i]]++;
for (int i = 1; i < N; i++)
s[i] = s[i - 1];
s[i] += s[i - 1];
for (int i = 0; i < n; i++)
sc[i] = s[N - 1] - s[b[i] - 1];
sc[i] = s[N - 1] - s[b[i]];
LL res = 0;
for (int i = 0; i <= n; i++)
......
......@@ -34,66 +34,73 @@
选择2、3、4。
```
以下错误的一项是?
## aop
### before
```cpp
#include <bits/stdc++.h>
#include <string>
#include <queue>
#include <set>
#include <cstring>
#include <cmath>
#include <algorithm>
#define MAX 1000000000
using namespace std;
int n, k, a[100010];
int b[4];
int flag = 0;
```
### after
```cpp
int main()
{
cin >> n >> k;
a[0] = MAX;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
dfs(a, n, 1);
return 0;
}
```
## 答案
```cpp
void dfs(int a[], int n, int s)
#define ll long long
using namespace std;
const int maxx = 1e5 + 100;
const int maxm = 1e3 + 100;
int a[maxx];
vector<int> p[maxm];
int n, k;
bool cmp(int a, int b) { return a > b; }
int main()
{
if (flag == 1)
return;
if (s == 4)
{
int sum = b[1] + b[2] + b[3];
if (sum % k == 0)
{
flag = 1;
cout << sum << endl;
}
return;
}
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
{
if (a[i] < a[s - 1])
{
b[s] = a[i];
dfs(a, n, s + 1);
}
}
scanf("%d", &a[i]);
p[a[i] % k].push_back(a[i]);
}
for (int i = 0; i < k; i++)
sort(p[i].begin(), p[i].end(), cmp);
int _max = 0;
for (int i = 0; i < k; i++)
{
if (p[i].size() == 0)
continue;
if ((3 * i == k || i == 0) && p[i].size() >= 3)
_max = max(_max, p[i][0] + p[i][1] + p[i][2]);
for (int j = 0; j < k; j++)
{
if (!p[j].size())
continue;
int z = k - (i + j) % k;
if (z < 0)
continue;
if (z == i && z == j)
continue;
else if ((i != j) && (z == i || z == j) && p[z].size() >= 2)
_max = max(_max, p[i][0] + p[j][0] + p[z][1]);
else if (i == j && p[i].size() >= 2 && p[z].size() >= 1)
_max = max(_max, p[i][0] + p[j][1] + p[z][0]);
else if (i != j && i != z && j != z && p[i].size() >= 1)
_max = max(_max, p[i][0] + p[j][0] + p[z][0]);
}
}
printf("%d\n", _max);
return 0;
}
```
## 选项
......@@ -101,83 +108,145 @@ void dfs(int a[], int n, int s)
### A
```cpp
void dfs(int a[], int n, int s)
#define FOR0(a, b) for (int i = a; i < b; ++i)
#define FORE(a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
typedef pair<int, int> pii;
ll dp[2][4][1005];
int n, k, a[100005], v[100005];
int main()
{
if (flag == 1)
return;
if (s == 4)
{
int sum = b[1] + b[2] + b[3];
if (sum % k == 0)
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i)
{
flag = 1;
cout << sum << endl;
scanf("%d", &a[i]);
v[i] = a[i];
v[i] %= k;
}
return;
}
for (int i = 1; i <= n; i++)
memset(dp, -0x3f3f3f3f, sizeof dp);
dp[0][0][0] = 0;
int d = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] < a[s - 1])
for (int j = 0; j < k; ++j)
{
b[s] = a[i];
dfs(a, n, s);
for (int p = 0; p <= 3; ++p)
{
if (i < p)
continue;
dp[d ^ 1][p][j] = max(dp[d ^ 1][p][j], dp[d][p][j]);
if (p > 0)
dp[d ^ 1][p][j] = max(dp[d ^ 1][p][j], dp[d][p - 1][((j - v[i]) % k + k) % k] + a[i]);
}
}
d ^= 1;
}
cout << dp[d][3][0] << endl;
return 0;
}
```
### B
```cpp
void dfs(int a[], int n, int s)
int n, k, ans = 0;
int temp[3], num[100005], vis[100005] = {0};
void dfs(int s)
{
if (flag == 1)
return;
if (s == 4)
if (s == 3)
{
int sum = b[1] + b[2] + b[3];
if (sum % k == 0)
{
flag = 1;
cout << sum << endl;
}
int t = temp[0] + temp[1] + temp[2];
if (t % k == 0 && t > ans)
ans = t;
return;
}
for (int i = 1; i <= n; i++)
else
{
if (a[i] < a[s + 1])
for (int i = 0; i < n; i++)
{
b[s] = a[i];
dfs(a, n, s + 1);
if (!vis[i])
{
temp[s] = num[i];
vis[i] = 1;
dfs(s + 1);
vis[i] = 0;
}
}
}
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &num[i]);
dfs(0);
printf("%d\n", ans);
return 0;
}
```
### C
```cpp
void dfs(int a[], int n, int s)
int N, k;
int main()
{
if (flag == 1)
return;
if (s == 4)
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> k;
vector<vector<int>> vec(k, vector<int>(3, -1));
for (int i = 0; i < N; ++i)
{
int sum = b[1] + b[2] + b[3];
if (sum % k == 0)
int temp;
cin >> temp;
int y = temp % k;
if (temp > vec[y][0])
{
flag = 1;
cout << sum << endl;
vec[y][2] = vec[y][1];
vec[y][1] = vec[y][0];
vec[y][0] = temp;
}
return;
else if (temp > vec[y][1])
{
vec[y][2] = vec[y][1];
vec[y][1] = temp;
}
for (int i = 1; i <= n; i++)
else if (temp > vec[y][2])
vec[y][2] = temp;
}
vector<int> ans(3);
int result = 0;
for (int i = 0; i < k; ++i)
for (int j = i; j < k; ++j)
{
int r = (k - i + k - j) % k;
ans[0] = vec[i][0];
if (i == j)
{
if (a[i] < a[s + 1])
ans[1] = vec[i][1];
if (r == i)
ans[2] = vec[i][2];
else
ans[2] = vec[r][0];
}
else
{
b[s] = a[i];
dfs(a, n, s);
ans[1] = vec[j][0];
if (r == i)
ans[2] = vec[i][1];
else if (r == j)
ans[2] = vec[j][1];
else
ans[2] = vec[r][0];
}
if (ans[0] != -1 && ans[1] != -1 && ans[2] != -1 && ans[1] + ans[2] + ans[0] > result)
result = ans[1] + ans[2] + ans[0];
}
cout << result;
}
```
......@@ -9,16 +9,15 @@
请你利用计算机的优势,帮助小明寻找答案。
以下哪一项不能得到正确答案?
## aop
### before
```cpp
#include <iostream>
#define LEFT 0
#define RIGHT 1
#include <bits/stdc++.h>
using namespace std;
int stage[40][2];
```
### after
......@@ -29,19 +28,32 @@ int stage[40][2];
## 答案
```cpp
int main()
int ans = 0;
int sum = 0;
vector<int> a(40, 0);
void dfs(int steps)
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
if (sum >= 39)
{
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
if ((steps - 1) % 2 == 0 && sum == 39)
ans++;
return;
}
cout << stage[39][RIGHT] << endl;
for (int i = 1; i <= 2; i++)
{
a[steps] = i;
sum += i;
dfs(steps + 1);
sum -= i;
}
}
int main()
{
dfs(0);
cout << ans << endl;
return 0;
}
```
......@@ -51,19 +63,24 @@ int main()
### A
```cpp
int main()
int ans = 0;
void dfs(int k, int n)
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
if (k == 39 && n % 2 == 0)
{
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
ans++;
}
cout << stage[39][LEFT] << endl;
if (k > 39)
return;
dfs(k + 1, n + 1);
dfs(k + 2, n + 1);
}
int main()
{
dfs(0, 0);
printf("%d\n", ans);
return 0;
}
```
......@@ -71,19 +88,27 @@ int main()
### B
```cpp
int main()
int countt = 0;
void f(int stair, int step)
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
if (stair < 0)
return;
if (step % 2 == 0 && stair == 0)
{
stage[i][LEFT] = stage[i + 1][RIGHT] + stage[i - 1][RIGHT];
stage[i][RIGHT] = stage[i + 1][LEFT] + stage[i - 1][LEFT];
countt++;
return;
}
cout << stage[39][RIGHT] << endl;
for (int i = 1; i <= 2; i++)
{
f(stair - i, step + 1);
}
}
int main(void)
{
f(39, 0);
cout << countt << endl;
return 0;
}
```
......@@ -91,6 +116,11 @@ int main()
### C
```cpp
#define LEFT 0
#define RIGHT 1
using namespace std;
int stage[40][2];
int main()
{
int i;
......@@ -100,10 +130,10 @@ int main()
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i + 1][RIGHT] + stage[i - 1][RIGHT];
stage[i][RIGHT] = stage[i + 1][LEFT] + stage[i - 1][LEFT];
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
}
cout << stage[39][LEFT] << endl;
cout << stage[39][RIGHT] << endl;
return 0;
}
```
# 第几天
y年m月d日是哪一年的第几天。
比如y年的1月1日是那一年的第一天,那么y年m月d日是哪一年的第几天。
**输入**
```
y m d
```
**输出**
输出一个整数
**样例**
比如y年的1月1日是那一年的第一天,那么2000年7月7日是那一年的第几天。
**输入**
```
2000 7 7
```
**输出**
```
189
```
## aop
### before
请通过以下代码,选出正确答案。
```cpp
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool is_leap(int year)
{
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int y, m, d, ans = 0;
......@@ -73,7 +46,26 @@ int main()
cout << ans << endl;
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
189
```
## 选项
......@@ -81,92 +73,17 @@ int main()
### A
```cpp
int main()
{
int y, m, d, ans = 0;
cin >> y >> m >> d;
int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (is_leap(y))
{
for (int i = 0; i < m; i++)
{
ans += L_m_d[i];
}
ans += d;
}
else
{
for (int i = 0; i < (m - 1); i++)
{
ans += nonL_m_d[i];
}
ans += d;
}
cout << ans << endl;
return 0;
}
188
```
### B
```cpp
int main()
{
int y, m, d, ans = 0;
cin >> y >> m >> d;
int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (is_leap(y))
{
for (int i = 0; i < (m - 1); i++)
{
ans += L_m_d[i];
}
ans += d;
}
else
{
for (int i = 0; i < m; i++)
{
ans += nonL_m_d[i];
}
ans += d;
}
cout << ans << endl;
return 0;
}
190
```
### C
```cpp
int main()
{
int y, m, d, ans = 0;
cin >> y >> m >> d;
int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (is_leap(y))
{
for (int i = 0; i < m; i++)
{
ans += L_m_d[i];
}
ans += d;
}
else
{
for (int i = 0; i < m; i++)
{
ans += nonL_m_d[i];
}
ans += d;
}
cout << ans << endl;
return 0;
}
191
```
......@@ -31,24 +31,13 @@
7 9
```
## aop
### before
请从以下四个选项中选择正确的代码填补空白处,实现方阵转置功能。
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int m, n;
......@@ -62,6 +51,27 @@ int main()
cin >> a[j][i];
}
}
__________________
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
......@@ -70,9 +80,6 @@ int main()
}
cout << endl;
}
return 0;
}
```
## 选项
......@@ -80,83 +87,38 @@ int main()
### A
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = 0; i < n; i++)
{
for (j = m; j > 0; j--)
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
cout << a[i-1][j] << " ";
}
cout << endl;
}
return 0;
}
```
### B
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = n; i > 0; i--)
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
cout << a[i][j-1] << " ";
}
cout << endl;
}
return 0;
}
```
### C
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = n; i > 0; i--)
for (i = 0; i < n; i++)
{
for (j = m; j > 0; j--)
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
cout << a[i-1][j-1] << " ";
}
cout << endl;
}
return 0;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册