当前位置:网站首页>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;
}
边栏推荐
- [target detection] YOLOv7 theoretical introduction + practical test
- PAT乙级 1001 害死人不偿命的(3n+1)猜想
- LeetCode 231. 2 的幂
- Seleniu: Common operations on elements
- 4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
- 25. Have you been asked these three common interview questions?
- Excel record of integer programming optimization model to solve the problem
- MySQL-Data Definition Language-DDLdatebase define language
- pytroch、tensorflow对比学习—专栏介绍
- MySQL-DML language-database operation language-insert-update-delete-truncate
猜你喜欢
(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
A,H,K,N
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
Pyspark Machine Learning: Vectors and Common Operations
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers
Robot_Framework: Assertion
MySQL-DML language-database operation language-insert-update-delete-truncate
JWL-11/2-99.9A电流继电器
HJS-DE1/2时间继电器
随机推荐
Seleniu: Common operations on elements
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
PAT serie b write the number 1002
Selenium:元素等待
y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
牛客多校2022第四场A,H,K,N
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
Selenium: element judgment
Selenium: Element wait
用控件当画笔获得bitmap代码记录
导致锁表的原因及解决方法
Selenium: browser operation
(2022牛客多校四)N-Particle Arts(思维)
JWL-11/2-99.9A电流继电器
Selenium: form switching
文件的异步读写
Selenium: Dropdown Box Actions
MySQL-数据定义语言-DDLdatebase define language
ApiFile
Pyspark Machine Learning: Vectors and Common Operations