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

update exercises

上级 83593f32
......@@ -15,24 +15,14 @@
#### 输出格式
输出一个整数表示答案。
#### 数据范围
```
2≤N≤100000,
0≤Ai≤109
1
2
```
#### 输入样例:
```
5
2 6 4 10 20
1
2
```
#### 输出样例:
```
10
1
```
#### 样例解释
包含 2、6、4、10、20 的最短的等差数列是 2、4、6、8、10、12、14、16、18、20。
......@@ -41,7 +31,17 @@
## aop
### before
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
```
### after
```cpp
......@@ -50,21 +50,98 @@
## 答案
```cpp
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int d = 0;
for (int i = 1; i < n; i++)
d = gcd(d, a[i] - a[0]);
if (d)
cout << (a[n - 1] - a[0]) / d + 1;
else
cout << n;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int d = 0;
for (int i = 1; i < n; i++)
d = gcd(d, a[i] - a[0]);
if (d)
cout << (a[n] - a[0]) / d + 1;
else
cout << n;
return 0;
}
```
### B
```cpp
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int d = 0;
for (int i = 1; i < n; i++)
d = gcd(d, a[i] - a[0]);
if (d)
cout << (a[n - 1] - a[0]) / d;
else
cout << n;
return 0;
}
```
### C
```cpp
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int d = 0;
for (int i = 1; i < n; i++)
d = gcd(d, a[i] - a[0]);
if (d)
cout << (a[n + 1] - a[0]) / d + 1;
else
cout << n;
return 0;
}
```
......@@ -15,30 +15,154 @@
## aop
### before
```cpp
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
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;
}
```
### after
```cpp
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;
}
```
## 答案
```cpp
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)
{
int m = first;
for (int j = 1; j < 10; ++j)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
}
}
}
return -1;
}
```
## 选项
### A
```cpp
int f(LL a[], int n)
{
for (int i = 0; i < n; ++i)
{
LL first = a[i];
for (int delta = 1; delta < a[n] - first; ++delta)
{
int m = first;
for (int j = 1; j < 10; ++j)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
}
}
}
return -1;
}
```
### B
```cpp
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)
{
int m = first;
for (int j = 1; j < 10; ++j)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
}
}
}
return -1;
}
```
### C
```cpp
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)
{
int m = first;
for (int j = 1; j < 10; ++j)
{
m += delta;
if (all.find(m) == all.end())
break;
if (m > a[n - 1])
break;
if (j == 9)
return delta;
}
}
}
return -1;
}
```
......@@ -4,7 +4,7 @@
先用1,2,3,…的自然数拼一个足够长的串
用这个串填充三角形的三条边。从上方顶点开始,逆时针填充。
比如,当三角形高度是8时:
![](https://img-blog.csdnimg.cn/20190203174943179.png)
![](https:
输入,一个正整数n(3<n<300),表示三角形的高度
输出,用数字填充的等腰三角形。
......@@ -15,26 +15,29 @@
5
#### 程序应该输出:
![](https://img-blog.csdnimg.cn/20190203175048400.png)
![](https:
### 再例如:
#### 输入:
10
#### 程序应该输出:
![](https://img-blog.csdnimg.cn/20190203175133907.png)
![](https:
### 再例如:
#### 输入:
15
#### 程序应该输出:
![](https://img-blog.csdnimg.cn/20190203175213126.png)
![](https:
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
string str;
stringstream ss;
```
### after
```cpp
......@@ -43,21 +46,249 @@
## 答案
```cpp
int main()
{
int n;
cin >> n;
int x = 2 * n - 1;
for (int i = 1; i <= 1500; i++)
{
string str1;
ss << i;
ss >> str1;
str += str1;
ss.clear();
}
int length = 4 * n - 4;
for (int i = 1; i <= n; i++)
{
if (i != n && i != 1)
{
for (int j = 1; j <= n + i - 1; j++)
{
if (j == n - i + 1)
{
cout << str[i - 1];
}
else if (j == 2 * n - (n - i + 1))
{
cout << str[4 * n - 4 - (i - 1)] << endl;
}
else
{
cout << '.';
}
}
}
else if (i == 1)
{
for (int x = 1; x <= n; x++)
{
if (x == n)
{
cout << '1' << endl;
}
else
{
cout << '.';
}
}
}
else
{
for (int m = 1; m <= 2 * n - 1; m++)
{
cout << str[n + (m - 2)];
}
}
}
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int n;
cin >> n;
int x = 2 * n - 1;
for (int i = 1; i <= 1500; i++)
{
string str1;
ss << i;
ss >> str1;
str += str1;
ss.clear();
}
int length = 4 * n - 4;
for (int i = 1; i <= n; i++)
{
if (i != n && i != 1)
{
for (int j = 1; j <= n + i - 1; j++)
{
if (j == n - i + 1)
{
cout << str[i - 1];
}
else if (j == 2 * n - (n - i + 1))
{
cout << str[4 * n - 4 - i] << endl;
}
else
{
cout << '.';
}
}
}
else if (i == 1)
{
for (int x = 1; x <= n; x++)
{
if (x == n)
{
cout << '1' << endl;
}
else
{
cout << '.';
}
}
}
else
{
for (int m = 1; m <= 2 * n - 1; m++)
{
cout << str[n + (m - 2)];
}
}
}
return 0;
}
```
### B
```cpp
int main()
{
int n;
cin >> n;
int x = 2 * n - 1;
for (int i = 1; i <= 1500; i++)
{
string str1;
ss << i;
ss >> str1;
str += str1;
ss.clear();
}
int length = 4 * n - 4;
for (int i = 1; i <= n; i++)
{
if (i != n && i != 1)
{
for (int j = 1; j <= n + i - 1; j++)
{
if (j == n - i + 1)
{
cout << str[i - 1];
}
else if (j == 2 * n - (n - i + 1))
{
cout << str[4 * n - 4 - (i + 1)] << endl;
}
else
{
cout << '.';
}
}
}
else if (i == 1)
{
for (int x = 1; x <= n; x++)
{
if (x == n)
{
cout << '1' << endl;
}
else
{
cout << '.';
}
}
}
else
{
for (int m = 1; m <= 2 * n - 1; m++)
{
cout << str[n + (m - 2)];
}
}
}
return 0;
}
```
### C
```cpp
int main()
{
int n;
cin >> n;
int x = 2 * n - 1;
for (int i = 1; i <= 1500; i++)
{
string str1;
ss << i;
ss >> str1;
str += str1;
ss.clear();
}
int length = 4 * n - 4;
for (int i = 1; i <= n; i++)
{
if (i != n && i != 1)
{
for (int j = 1; j <= n + i - 1; j++)
{
if (j == n - i + 1)
{
cout << str[i - 1];
}
else if (j == 2 * n - (n - i + 1))
{
cout << str[4 * n - 4 + i] << endl;
}
else
{
cout << '.';
}
}
}
else if (i == 1)
{
for (int x = 1; x <= n; x++)
{
if (x == n)
{
cout << '1' << endl;
}
else
{
cout << '.';
}
}
}
else
{
for (int m = 1; m <= 2 * n - 1; m++)
{
cout << str[n + (m - 2)];
}
}
}
return 0;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册