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

add exercises

上级 7151ee17
{
"node_id": "algorithm-95fa7ac83e7d4750b7aae3d4c2b0e797",
"keywords": [
"蓝桥杯",
"螺旋折线"
],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
如图所示的螺旋折线经过平面上所有整点恰好一次。
对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。
例如```dis(0, 1)=3, dis(-2, -1)=9```
给出整点坐标(X, Y),你能计算出dis(X, Y)吗?
#### 输入格式
```
X和Y
对于40%的数据,-1000 <= X, Y <= 1000
对于70%的数据,-100000 <= X, Y <= 100000
对于100%的数据, -1000000000 <= X, Y <= 1000000000
```
#### 输出格式
```
输出dis(X, Y)
```
#### 样例输入
```
0 1
```
#### 样例输出
```
3
```
\ No newline at end of file
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
long long sum = 0;
if ((y < x) && (-y <= x))
{
sum += x > 1 ? (long long)(4 * (2 + (abs(x) - 1) * (abs(x) - 2))) : 0; //求前n个正方形周长的等差数列和
sum += (long long)x > 0 ? (4 * x + (x - y)) : (y - x);
}
else
{
sum += y > 1 ? (long long)(4 * (2 + (abs(y) - 1) * (abs(y) - 2))) : 0; //求前n个正方形周长的等差数列和
sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - y - x);
}
cout << sum << endl;
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f4968aaaa7a34063a534a664765f429d"
}
\ No newline at end of file
# 螺旋折线
如图所示的螺旋折线经过平面上所有整点恰好一次。
对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。
例如`dis(0, 1)=3, dis(-2, -1)=9`
给出整点坐标(X, Y),你能计算出dis(X, Y)吗?
**输入格式**
```
X和Y
对于40%的数据,-1000 <= X, Y <= 1000
对于70%的数据,-100000 <= X, Y <= 100000
对于100%的数据, -1000000000 <= X, Y <= 1000000000
```
**输出格式**
```
输出dis(X, Y)
```
**样例输入**
```
0 1
```
**样例输出**
```
3
```
以下程序实现了该功能,请你补全空白处内容:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
long long sum = 0;
if ((y < x) && (-y <= x))
{
sum += x > 1 ? (long long)(4 * (2 + (abs(x) - 1) * (abs(x) - 2))) : 0;
sum += (long long)x > 0 ? (4 * x + (x - y)) : (y - x);
}
else
{
sum += y > 1 ? (long long)(4 * (2 + (abs(y) - 1) * (abs(y) - 2))) : 0;
__________________
}
cout << sum << endl;
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - y - x);
```
## 选项
### A
```cpp
sum += (long long)y > 0 ? (2 * y + x) : (6 * y - y - x);
```
### B
```cpp
sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - x);
```
### C
```cpp
sum += (long long)y > 0 ? (2 * y + x) : (6 * y - x);
```
......@@ -46,6 +46,7 @@
**样例说明**
按照如下方式镶嵌珠子得到最大价值 20,括号内表示镶嵌的装饰珠的种类编号:
```
1: (1)
2: (1) (2)
......@@ -54,6 +55,7 @@
5: (1)
6: (2)
```
4 颗技能 1 装饰珠,4 颗技能 2 装饰珠 $W_1(4) + W_2(4) = 5 + 15 = 20。W_1(4)+W_2(4)=5+15=20$。
以下<span style="color:red">错误</span>的一项是?
......
......@@ -3,7 +3,7 @@
如图所示的螺旋折线经过平面上所有整点恰好一次。
对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。
例如```dis(0, 1)=3, dis(-2, -1)=9```
例如`dis(0, 1)=3, dis(-2, -1)=9`
给出整点坐标(X, Y),你能计算出dis(X, Y)吗?
......@@ -36,6 +36,34 @@ X和Y
3
```
以下程序实现了该功能,请你补全空白处内容:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
long long sum = 0;
if ((y < x) && (-y <= x))
{
sum += x > 1 ? (long long)(4 * (2 + (abs(x) - 1) * (abs(x) - 2))) : 0;
sum += (long long)x > 0 ? (4 * x + (x - y)) : (y - x);
}
else
{
sum += y > 1 ? (long long)(4 * (2 + (abs(y) - 1) * (abs(y) - 2))) : 0;
__________________
}
cout << sum << endl;
return 0;
}
```
## aop
### before
......@@ -53,7 +81,7 @@ X和Y
## 答案
```cpp
sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - y - x);
```
## 选项
......@@ -61,17 +89,17 @@ X和Y
### A
```cpp
sum += (long long)y > 0 ? (2 * y + x) : (6 * y - y - x);
```
### B
```cpp
sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - x);
```
### C
```cpp
sum += (long long)y > 0 ? (2 * y + x) : (6 * y - x);
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册