10038 - Jolly Jumpers
来源:互联网 发布:淘宝咸鱼网手机版 编辑:程序博客网 时间:2024/05/20 15:39
题目
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=30&problem=979&mosmsg=Submission+received+with+ID+17410928
解题思路
1. 模拟题
2. 用hash判断diff(1~n-1)
3. 注意diff可能超过n-1,所以要避免对hash表的越界访问
4. 每行都要输出一个换行符
通过代码
#include<stdio.h>#include<string.h>#define N 3000bool diff[N];int num[N];int main(){#ifdef DEBUG freopen("in","r",stdin); freopen("out","w",stdout);#endif int n; int tmp; bool jolly; while(scanf("%d",&n)!=EOF){ //init jolly=true; memset(diff,0,sizeof(diff)); //input scanf("%d",&num[0]); for(int i=1;i<n;++i){ scanf("%d",&num[i]); tmp=num[i]-num[i-1]; if(tmp<0) tmp=tmp*(-1); if(tmp<=n-1) diff[tmp]=true; } //check for(int i=1;i<n;++i) if(!diff[i]){ jolly=false; break; } //print results if(jolly) printf("Jolly\n"); else printf("Not jolly\n"); } return 0;}
运行截图
0 0
- UVa 10038 Jolly Jumpers
- 10038 - Jolly Jumpers
- UVa 10038 - Jolly Jumpers
- uva 10038 Jolly Jumpers
- UVa 10038 - Jolly Jumpers
- UVa 10038 - Jolly Jumpers
- UVa 10038 Jolly Jumpers
- 10038 - Jolly Jumpers
- UVa 10038 Jolly Jumpers
- UVa OJ 10038-Jolly Jumpers
- UVa OJ 10038 - Jolly Jumpers
- Jolly Jumpers
- jolly jumpers
- UVa Problem Solution: 10038 - Jolly Jumpers
- UvaOJ 10038 - Jolly Jumpers 题解以及代码
- fjnu 1532 Jolly Jumpers
- fjnu 1591 Jolly Jumpers
- 1591Jolly Jumpers
- C++第六次上机实验
- Java 强制类型转换
- c++第六次作业
- C++上机实验6-矩阵的求和
- 求解组合数取模模板
- 10038 - Jolly Jumpers
- CentOS 6.5 下的截图方法
- 深入理解Java的接口和抽象类
- java登录界面各项设置(enter登录)
- hdu1495~广搜
- centos添加第三方源
- 【Socket编程】篇五之IO同步、异步、阻塞、非阻塞
- skb相关的函数
- Python爬虫实战一之爬取糗事百科段子