poj 2575 Jolly Jumpers

简介:

很奇怪的一道题,受了discuss的误导,居然当n==1的时候输出Jolly是错的,后来去掉反而正确了。。。

一个flag就搞定的东西,搞不懂为什么有些人用到排序,真是没事找事。。。

题目解析:求给出序列的各个值之差是否能覆盖1~n-1,要是能,输出:"Jolly",否则输出:"Not jolly",其实不难,只要把各个值得绝对值求出来,看能否覆盖1~n-1。


#include <stdio.h>
#include <string.h>

int flag[3002];

inline int myAbs(int a) { return a>0?a:(-a); }

int main()
{
	int n;

	int i;
	int x,y;
	while(~scanf("%d",&n))
	{
		memset(flag,0,sizeof(flag));

		scanf("%d",&x);
		for(i=1;i<n;i++)
		{
			scanf("%d",&y);
			flag[myAbs(y-x)]=1;
			x=y;
		}

		for(i=1;i<n;i++)
			if(flag[i]==0)
				break;

		if(i==n)
			printf("Jolly\n");

		else
			printf("Not jolly\n");
	}

	return 0;
}



相关文章
|
人工智能 BI
poj-3185-开关问题
描述   牛一行20他们喝的水碗。碗可以那么(面向正确的为清凉水)或颠倒的(一个位置而没有水)。他们希望所有20个水碗那么,因此用宽鼻子翻碗。   嘴太宽,他们不仅翻转一碗还碗的碗两侧(总共三个或三个——在两端的情况下碗——两碗)。
784 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1035 0
|
机器学习/深度学习 算法
|
测试技术
|
算法 计算机视觉
最小割-poj-2914
poj-2914-Minimum Cut Description Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must b
1532 0
|
存储
大数加法-poj-1503
poj-1503-Integer Inquiry Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking vari
1100 0
|
SDN
poj 2886 Who Gets the Most Candies?
点击打开poj 2886 思路: 求因子数+单点更新 分析: 1 题目的意思是有n个人构成一个环,刚开始是第k个人先出来。每个人有一个名字和数值A,如果A为正数,那么下一个出去的人是他左边的第A个人,如果是负数那么出去的将是右边的第A个人 2 这么我们要注意一下,因为n个人是围城一圈,那么左边就是顺时针方向,右边就是逆时针方向 3 那么我们就可以来推没一次出去的人的在剩下中是第几个。
764 0