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

update exercises

上级 4c49dc90
......@@ -11,7 +11,11 @@
## aop
### before
```cpp
#include <iostream>
#define LEFT 0
#define RIGHT 1
using namespace std;
int stage[40][2];
```
### after
```cpp
......@@ -20,21 +24,77 @@
## 答案
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
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][RIGHT] << endl;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
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;
return 0;
}
```
### B
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
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];
}
cout << stage[39][RIGHT] << endl;
return 0;
}
```
### C
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
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];
}
cout << stage[39][LEFT] << endl;
return 0;
}
```
......@@ -16,7 +16,11 @@ x星的国王有个怪癖,他只喜欢数字3,5和7。
## aop
### before
```cpp
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
```
### after
```cpp
......@@ -25,21 +29,139 @@ x星的国王有个怪癖,他只喜欢数字3,5和7。
## 答案
```cpp
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++)
{
long long b = lucky * ok[i];
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
}
}
return 0;
}
```
## 选项
### A
```cpp
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++)
{
long long b = lucky * ok[i + 1];
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
}
}
return 0;
}
```
### B
```cpp
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++)
{
long long b = lucky * ok[i] + 1;
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
}
}
return 0;
}
```
### C
```cpp
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++)
{
long long b = lucky + ok[i];
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
}
}
return 0;
}
```
......@@ -13,7 +13,7 @@ int main()
if (is_leap(y)) //判断闰年
{
for (int i = 0; i < (m - 1); i++) //记录1-(m-1)月天数
for (int i = 0; i < m; i++) //记录1-(m-1)月天数
{
ans += L_m_d[i];
}
......@@ -21,7 +21,7 @@ int main()
}
else
{
for (int i = 0; i < (m - 1); i++)
for (int i = 0; i < m; i++)
{
ans += nonL_m_d[i];
}
......
......@@ -23,7 +23,12 @@ y m d
## aop
### before
```cpp
#include <iostream>
using namespace std;
bool is_leap(int year)
{
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
```
### after
```cpp
......@@ -32,21 +37,122 @@ y m d
## 答案
```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++) //记录1-(m-1)月天数
{
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;
}
```
## 选项
### 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++) //记录1-(m-1)月天数
{
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;
}
```
### 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++) //记录1-(m-1)月天数
{
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;
}
```
### 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++) //记录1-(m-1)月天数
{
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;
}
```
......@@ -35,6 +35,15 @@ C = [C1, C2, ... CN],
## aop
### before
```cpp
#include <iostream>
#include <cstring>
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
......@@ -44,21 +53,145 @@ C = [C1, C2, ... CN],
## 答案
```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]++;
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;
}
```
## 选项
### A
```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]++;
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] - s[b[i]];
LL res = 0;
for (int i = 0; i <= n; i++)
res += (LL)sa[i] * sc[i];
cout << res;
}
```
### 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]++;
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;
}
```
### C
```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]++;
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] - 1];
LL res = 0;
for (int i = 0; i <= n; i++)
res += (LL)sa[i] * sc[i];
cout << res;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册