当前位置:网站首页>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;
}
边栏推荐
- redis集群的三种方式
- Mxnet implementation of densenet (dense connection network)
- IM系统-消息流化一些常见问题
- 2022年下半年软考信息安全工程师如何备考?
- 包管理 apt,dpkg
- 刷题-洛谷-P1152 欢乐的跳
- Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
- Mutex lock, spin lock, read-write lock... Clarify their differences and applications
- HTTP cache tongtianpian, there may be something you want
- adb通过Wi-Fi连接小米手机
猜你喜欢

Applet starts wechat payment

Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?

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

【力扣】1030.距离顺序排列矩阵单元格

刷题-洛谷-P1151 子数整数

ADB connects to Xiaomi mobile phone via Wi Fi
Congestion control of TCP
![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
HTTP cache tongtianpian, there may be something you want

刷题-洛谷-P1075 质因数分解
随机推荐
The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)
MXNet对DenseNet(稠密连接网络)的实现
音视频技术开发周刊 | 255
0719RHCSA
刷题-洛谷-P1047 校门外的树
hcip第九天笔记
Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
@Wrap decorator
Excel add key run macro
In order to improve efficiency, there are various problems when using parallelstream
Hcip eighth day experiment
The migration of arm architecture to alsa lib and alsa utils is smooth
ES6 array de duplication new set()
Canal realizes MySQL data synchronization
leetcode202---快乐数
adb通过Wi-Fi连接小米手机
[force deduction] 1030. Arrange matrix cells in distance order
redis集群的三种方式
Applet enterprise red envelope function