Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

真题出的真没意思。你好歹给点限制啊,随便输出一个,我随便输出一个你又给我错?

Posted by qq1250173534 at 2020-03-02 13:09:32 on Problem 1426
//换long long 不然就会错
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define ll long long
int cnt = 0;
queue<ll>q;
void bfs(int n)
{
	while(!q.empty()){
		ll ptr = q.front(),p;
		q.pop();
		if(ptr % n == 0){
			printf("%lld\n",ptr);
			return ;
		}
		for(int i = 0;i < 2;i++){
			if(i == 0){
				p = ptr*10+1;
				q.push(p);
			}
			else{
				p = ptr*10;
				q.push(p);
			}
		}
	}
}
int main()
{
	int n;
	while(~scanf("%d",&n) && n){
		while(!q.empty()){
			q.pop();
		}
		q.push(1);
		bfs(n);
	}
	return 0;
}
//害的我半天不敢下手,想出了4种转移状态,每一位变化1或者0,尾部+1或者尾部+0

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator