当前位置:网站首页>uva10825
uva10825
2022-08-01 05:20:00 【Knife stabs the bear】
#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;
}
边栏推荐
- Hunan institute of technology in 2022 ACM training sixth week antithesis
- JWL-11/2-99.9A电流继电器
- (2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
- Seleniu:元素常用操作
- Robot_Framework: commonly used built-in keywords
- What should I do if the neural network cannot be trained?
- WPF项目-初步了解数据绑定 binding
- Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers
- 解决浏览器滚动条导致的页面闪烁问题
- (Codeforce 757) E. Bash Plays with Functions
猜你喜欢
Excel record of integer programming optimization model to solve the problem
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)
【MySQL必知必会】 表的优化 | 充分利用系统资源
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
A,H,K,N
(2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)
leetcode125 验证回文串
Selenium:操作Cookie
随机推荐
pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
Selenium: Introduction
初识shell脚本
Selenium:上传、下载文件
可持久化线段树
Causes and solutions of lock table
The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
I met a shell script
[MySQL] 多表查询
pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)
七、MFC序列化机制和序列化类对象
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
MySQL-Data Definition Language-DDLdatebase define language
Hunan institute of technology in 2022 ACM training sixth week antithesis
Selenium:浏览器操作
The method of solving stored procedure table name passing through variable in mysql
挑战52天背完小猪佩奇(第01天)
Selenium:表单切换
state compressed dp