Hdu 6937 yiding Number

题意:一个正整数满足以下两个条件被称为yiding number
1: 1是yiding number
2: 如果n是yiding number数,那么 5n+13, 13n+5, 5n−13, 13n−5 也是yiding number

#include<iostream>
#include<stdio.h>
#include<queue>
#include<map>
using namespace std;

typedef long long ll;
queue<int> q;
map<int,bool> mp;

int inf=1000000; 
int main()
{
	//freopen("11.txt","r",stdin);
	
	q.push(1);
	 
	while( !q.empty() )
	{
		int x=q.front();
		q.pop();
	//	if( mp.find(x)==mp.end() && x>0 && x<=inf )
	    mp[x]=true;
		
		int a[4];
		a[0]=5*x+13 ,a[1]=13*x+5 ,a[2]=5*x-13,a[3]=13*x-5;
		for(int i=0;i<4;i++)
		{
			if(a[i]>0 && a[i]<=inf && mp.find(a[i])==mp.end() )
			   q.push(a[i]);
		}
	}
	
	int n;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		if(mp.find(x)!=mp.end())
		  cout<<"Yes"<<endl;
		else
		   cout<<"No"<<endl; 
	}
	return 0;
}
 
上一篇:HDU-P1087:Super Jumping! Jumping! Jumping![动态规划]


下一篇:HDU-1272小希的迷宫(并查集的运用)