您的位置:首页 > 其它

poj 2575

2012-10-11 18:59 211 查看
题目连接:http://poj.org/problem?id=2575

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

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int flag[3001], num[3001];
int Fac(int n) {
memset(flag,0,sizeof(flag));
memset(num,0,sizeof(num));
int i,j,k,f,res=0;
for(i=1;i<=n;i++)
cin>>num[i];
for(k=2;k<=n;k++){
f=abs(num[k]-num[k-1]);
if(f<3001)
flag[f]=f;
}
for(j=1;j<n;j++)
if(!flag[j]){
res=1;break;
}
if(res)
cout<<"Not jolly"<<endl;
else
cout<<"Jolly"<<endl;
return 0;
}
int main() {
int n;
while(cin>>n)
Fac(n);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: