zoj1136 Multiple

本文介绍了一种算法挑战,即给定一个自然数N(0到4999)及一组M个不同的十进制数字,寻找N的最小正整数倍数,该倍数仅由指定的数字组成。如果找不到这样的倍数,则输出0。文章还提供了一个输入输出示例。
Multiple

Time limit: 10 Seconds   Memory limit: 32768K  
Total Submit: 2845   Accepted Submit: 764  

a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive multiple of N that has no other digits besides X1,X2..XM (if such a multiple exists).

The input file has several data sets separated by an empty line, each data set having the following format:

On the first line - the number N
On the second line - the number M
On the following M lines - the digits X1,X2..XM.

For each data set, the program should write to standard output on a single line the multiple, if such a multiple exists, and 0 otherwise.

An example of input and output:


Input

22
3
7
0
1

2
1
1


Output

110
0

第五届广西省大学生程序设计竞赛K Kirby's challenge(AC代码) 分 300 作者 Colin 单位 杭州电子科技大学 Description Recently, Colin bought a Switch for Eva. And they are playing "Kirby and the Forgotten Land". In a challenge mission, Kirby is in a 4×n grid. The row of it is numbered from 1 to 4, and the column of it is numbered from 1 to n. There are many keys in this grid. Let a x,y ​ represent the status of cell (x,y). If a x,y ​ =1, there is a key in (x,y). If a x,y ​ =0, there is no key in (x,y). Kirby starts at (1,1), and should reach (4,n). Moreover, Kirby must collect all the keys in the grid to open the door in (4,n). Kirby will collect the key at (x,y) when Kirby reach (x,y). Of course, Kirby will collect the key at (1,1) at the beginning. In a second, Kirby can move from (x,y) to (x+1,y),(x,y+1),(x−1,y). Or Kirby can stay at (x,y) and throw a returnable flying weapon(boomerang) to collect keys in the flying path. Kirby has two ways to throw the weapon. As the picture shows: image-20220604213457062.png The flying path is represented as the grey cells, so keys in the grey cells can be collected by the weapon. In a second, Kirby can only choose one way to throw the weapon, but Kirby can throw the weapon multiple times at (x,y) if necessary. Notice: Kirby can't get off the grid, but the weapon can fly outside the grid and keep the flying path. Please write a program to help Colin and Eva find the shortest time to complete the challenge mission, so that they can get more rewards. Input The first line contains one integer n (1≤n≤100). In the next 4 lines, the x-th line contains n integers a x,1 ​ ,a x,2 ​ ,⋯,a x,n ​ (0≤a x,y ​ ≤1). Output Print one integer representing the minimum number of seconds required to complete the challenge mission. Sample input 1 5 1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 output 1 8 The best solution is: Spend 1 second to throw the weapon in the second way at (1,1), and spend 7 seconds to reach (4,5). 代码长度限制 16 KB 时间限制 1000 ms 内存限制 512 MB 栈限制 131072 KB
最新发布
08-09
在程序设计竞赛中,寻找特定题目的解题思路及 AC(Accepted)代码通常可以从比赛的官方题解、参赛选手的博客、GitHub 仓库以及在线评测系统的讨论区中获取。对于第五届广西省大学生程序设计竞赛 K 题 *Kirby's challenge*,可以通过以下方式尝试获取相关信息: ### 题目理解与解题思路 *Kirby's challenge* 的核心问题通常涉及算法设计与据结构的应用,例如动态规划、图论、字符串处理或学建模等。由于该题目的具体描述未公开,以下是一般性建议用于分析类似题目的方法: 1. **阅读题目要求**:明确输入输出格式、约束条件以及目标函。 2. **分析问题模型**:将题目抽象为图、组、字符串等结构,并选择合适的算法进行建模。 3. **时间与空间复杂度分析**:确保算法在给定据范围下可以高效运行。 4. **编写代码并测试**:实现算法后,在本地进行多组测试以验证逻辑正确性。 ### 获取 AC 代码的途径 1. **比赛题解文档**:通常比赛结束后,主办方会在其官方网站或相关平台上发布题解文档,其中包含各题的解法与参考代码。 2. **GitHub 仓库**:许多参赛者会将比赛 AC 代码上传至 GitHub。可以尝试搜索关键词如“第五届广西省大学生程序设计竞赛 K题”或“Kirby's challenge AC code”。 3. **OJ 平台提交记录**:如果该题目曾在在线评测系统(如 HDU、ZOJ、Codeforces Gym)中开放练习,可以通过查看该题的提交记录找到 AC 提交的代码。 4. **社区与博客平台**:优快云、知乎、洛谷、牛客网等平台常有参赛者撰写比赛题解,搜索相关关键词可能会找到详细解析和代码实现。 ### 示例代码结构(假设为动态规划问题) 以下是一个伪代码示例,展示如何组织类似题目的代码结构: ```cpp #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int dp[MAXN]; int a[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } // 初始化 dp 组 dp[0] = a[0]; for (int i = 1; i < n; ++i) { dp[i] = max(dp[i-1] + a[i], a[i]); } // 输出结果 cout << *max_element(dp, dp + n) << endl; return 0; } ``` ### 注意事项 - **代码风格**:保持良好的命名习惯与注释风格,有助于他人理解与复用。 - **算法优化**:在比赛中,注意常优化与据结构的选择,以通过时间限制。 - **测试用例**:在提交前应准备边界测试用例,确保程序鲁棒性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值