当前位置:网站首页>uva10825
uva10825
2022-08-01 05:13:00 【小刀刺大熊】
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
int n, m,vis[404], ans[10];
bool check(int c) {
int sum = 0, val = 0, cnt[404] = {
0};
for (int i = m - 1; i >= 0; i--) {
sum += ans[i] * c;
int t = sum % n;
if (++cnt[t] > vis[t]) return false;
sum /= n;
}
return true;
}
bool solve(int last) {
int sum = last;
memset(vis, 0, sizeof(vis));
ans[m - 1] = last;
vis[last]++;
for (int i = m - 2; i >= 0; i--) {
sum = (sum + last) % n;
ans[i] = sum;
vis[sum]++;
}
sort(ans, ans + m - 1);
do {
bool ok = true;
for (int i = 2; i <= m; i++) {
if (!check(i)) {
ok = false;
break;
}
}
if (ok) return true;
} while (next_permutation(ans, ans + m - 1));
return false;
}
int main()
{
while (cin >> m >> n && (m || n)) {
bool ok = false;
for (int i = 1; i < n; i++) {
if (solve(i)) {
ok = true;
break;
}
}
if (ok) {
for (int i = 0; i < m; i++) {
if (i) cout << " "<< ans[i] ;
else cout << ans[i];
}
cout << endl;
}else
cout << "Not found." << endl;
}
return 0;
}
边栏推荐
- DL-31/6电流继电器
- API Design Notes: The pimpl trick
- y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
- (2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
- Selenium: element positioning
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- LeetCode 9. 回文数
- ApiFile
- vim配置+ctag像source insight一样方便阅读代码
- (2022牛客多校四)A-Task Computing (排序+动态规划)
猜你喜欢

Excel record of integer programming optimization model to solve the problem

(Codeforce 757)E. Bash Plays with Functions(积性函数)

Power button (LeetCode) 212. The word search II (2022.07.31)

零序电流继电器器JL-8C-12-2-2

PAT乙级 1002 写出这个数

Robot growth in China

typescript27 - what about enumeration types

Selenium: Popup Handling

NDK does not contain any platforms problem solving

About making a progress bar for software initialization for Qt
随机推荐
leetcode125 验证回文串
Selenium:下拉框操作
Robot_Framework: Assertion
[MySQL] 多表查询
(Codeforce 757)E. Bash Plays with Functions(积性函数)
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Malicious attacks on mobile applications surge by 500%
文件的异步读写
(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
可视化全链路日志追踪
报错:AttributeError: module ‘matplotlib’ has no attribute ‘figure’
微信小程序用户登录auth.code2Session接口开发
Robot_Framework:断言
图片更新之后Glide加载依旧是原来的图片问题
(2022牛客多校四)A-Task Computing (排序+动态规划)
Selenium: form switching
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
USB3.0:VL817Q7-C0的LAYOUT指南(三)