国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ 1426 Find The Multiple dfs or 暴力

2019-11-14 09:14:56
字體:
來源:轉載
供稿:網友
Given a positive integer n, write a PRogram to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.InputThe input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.OutputFor each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.Sample Input
26190Sample Output
10100100100100100100111111111111111111
題意:
給出一個整數n,(1 <= n <= 200)。求出任意一個它的倍數m,要求m必須只由十進制的'0'或'1'組成。
思路:
要不是放在這個搜索專題里我不會用搜索去解的,我肯定會暴力去解的;其實搜索也是一種枚舉啊,
我這里用了兩種方法;
dfs:
每個數都會有答案,因為都必須是0 1 組成的十進制,我們就每次去dfs他們的十倍和十倍+1;
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int flag;void dfs(unsigned long long m,int x,int k){	if(flag||k>=19)//這里的flag標志位,找到了直接回溯返回	return ;	if(m%x==0)	{		flag=1;		printf("%I64u/n",m);		return ;	}	dfs(m*10,x,k+1);	dfs(m*10+1,x,k+1);	return ;	}int main(){	int n;	while(cin>>n&&n)	{		flag=0;		dfs(1,n,0);	}	return 0; } 
暴力:
將每個數存數組,然后根據存放位置的奇偶來決定是否+1,然后直到能整除!
#include<cstdio>#include<iostream>#define ll long long #define N 6*100010using namespace std;ll a[N];int n;int main(){	int i;	while(cin>>n&&n)	{		a[1]=1;//初始設置為1		int flag=0;		for(i=1;i<=N;i++)		{			a[i]=a[i/2]*10+i%2;//寫幾個數找一個規律,			if(a[i]%n==0)			{				printf("%lld/n",a[i]);				flag=1;				break;			}		}	}	return 0; } 

上一篇:cron表達式詳解

下一篇:Unity 單例模式

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 册亨县| 临澧县| 雷州市| 孝感市| 柘荣县| 正定县| 麻栗坡县| 三亚市| 泗洪县| 沁阳市| 依安县| 同心县| 晋城| 新竹市| 太仆寺旗| 满城县| 竹北市| 平武县| 昌乐县| 迁安市| 崇州市| 龙井市| 乌拉特前旗| 日照市| 吴桥县| 寿光市| 绥德县| 嘉鱼县| 青海省| 喀什市| 天水市| 建平县| 绍兴市| 苍山县| 连平县| 双峰县| 甘泉县| 龙江县| 东乡县| 安化县| 泗洪县|