当前位置:网站首页>Brush questions - Luogu -p1152 happy jump
Brush questions - Luogu -p1152 happy jump
2022-07-25 13:47:00 【Song Xiangshang_ UP】
P1152 Happy jump -C Language
1、 subject

2、 The problem solving process
result :
Code :
// Luogu P1152 Happy jump
#include <stdio.h>
#define NUM 1000//1≤n≤1000
int main() {
int n;//n Elements
int a[NUM];//n An integer array of elements
int d_value[NUM] = {
0 };
int j = 0;
int i;
int temp;
scanf("%d", &n);
for (i = 0; i < n; i++) {
if (i == 0) {
scanf("%d", &a[i]);
}
else {
scanf("%d", &a[i]);
temp= a[i] - a[i - 1];
d_value[j] = temp > 0 ? temp : (-1 * temp);// The absolute value
j++;
}
}
/* printf(" The data of the difference array is :\n"); for (i = 0; i < n-1; i++) {// after n-1 Number of differences printf(" %d ", d_value[i]); }*/
int k = n - 1;
// Use bubble sorting to determine whether there are duplicate values , And judge the endpoints at both ends
for (i = 0; i < k-1 ; i++) {
// Conduct k-1 Secondary effervescence
for (j = 1; j <k; j++) {
if (d_value[j] == d_value[j - 1]) {
printf("Not jolly");// Jump not in line with joy
return 0;
}
else if (d_value[j - 1] > d_value[j]) {
temp = d_value[j-1];
d_value[j-1] = d_value[j];
d_value[j] = temp;
}
}
}
/* printf("\n The data of the sorted difference array is :\n"); for (i = 0; i < n-1; i++) { printf(" %d ", d_value[i]); } printf("\n");*/
if (d_value[0] != 1) {
printf("Not jolly");// Jump not in line with joy
}
else if(d_value[n - 2] != (n - 1)){
printf("Not jolly");// Jump not in line with joy
}
else {
printf("Jolly");// Jump in line with joy
}
/* if ((d_value[0] == 1) & (d_value[n - 2] == n - 1)) { printf("Jolly");// Jump in line with joy } else { printf("Not jolly");// Jump not in line with joy }*/
return 0;
}
边栏推荐
- MXNet对DenseNet(稠密连接网络)的实现
- Introduction and features of numpy (I)
- Namespaces and libraries
- Uncaught SyntaxError: Octal literals are not allowed in strict mode.
- What is your revenue rank among global developers in 2022?
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- VIM basic operation summary
- I2C can also be powered on by bus!
- 【配置Hifive1-revB】设备管理器中不识别端口,Can not connect to J-Link via USB的解决办法
- 职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
猜你喜欢

ADB connects to Xiaomi mobile phone via Wi Fi

领域驱动模型设计与微服务架构落地-模型设计

Redux usage and analysis

嵌入式代码如何进行重构?
[email protected] (using password:YES)"/>The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)

Introduction to jupyter notebook
![Error of Tencent cloud [100007] this env is not enable anonymous login](/img/a2/a209a0d94e3fbf607242c28d87e2dd.png)
Error of Tencent cloud [100007] this env is not enable anonymous login

0715RHCSA

伯克利博士『机器学习工程』大实话;AI副总裁『2022 ML就业市场』分析;半导体创业公司大列表;大规模视频人脸属性数据集;前沿论文 | ShowMeAI资讯日报
![[force buckle] 645. Wrong set](/img/0a/143d8996cbae9921652c4d4fb31046.png)
[force buckle] 645. Wrong set
随机推荐
并发编程之阻塞队列
命名空间与库
MXNet对DenseNet(稠密连接网络)的实现
刷题-洛谷-P1150 Peter的烟
Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
HTTP cache tongtianpian, there may be something you want
嵌入式代码如何进行重构?
高版本MySQL服务端安装不上怎么办,忘记密码(MySQL8.0.29)?
Error of Tencent cloud [100007] this env is not enable anonymous login
刷题-洛谷-P1059 明明的随机数
@Classmethod decorator
Audio and video technology development weekly | 255
Introduction and features of numpy (I)
Peripheral system calls SAP's webapi interface
Hcip seventh day notes
0719RHCSA
Explain the precision of floating point numbers in detail
0717RHCSA
hcip第十天笔记
ADB connects to Xiaomi mobile phone via Wi Fi