当前位置:网站首页>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;
}
边栏推荐
- (Codeforce 757)E. Bash Plays with Functions(积性函数)
- II. Binary tree to Offer 68 - recent common ancestor
- LeetCode 27. 移除元素
- MySQL实践总结-
- 将CSV文件快速导入MySQL中
- Selenium:操作Cookie
- WPF入门项目必知必会-初步了解数据绑定 binding
- MySQL-DML language-database operation language-insert-update-delete-truncate
- vim configuration + ctag is as easy to read code as source insight
- leetcode125 验证回文串
猜你喜欢
(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
Selenium: Popup Handling
UE4 从鼠标位置射出射线检测
USB3.0:VL817Q7-C0的LAYOUT指南(三)
【MySQL必知必会】 表的优化 | 充分利用系统资源
pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)
零序电流继电器器JL-8C-12-2-2
pytorch、tensorflow对比学习—计算图和微分机制
字符中的第一个唯一字符
The difference between scheduleWithFixedDelay and scheduleAtFixedRate
随机推荐
程序员代码面试指南 CD15 生成窗口最大值数组
将CSV文件快速导入MySQL中
MySQL实践总结-
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
High Numbers | 【Re-integration】Line Area Score 880 Examples
Check控件
MySQL-Data Definition Language-DDLdatebase define language
Excel record of integer programming optimization model to solve the problem
图片更新之后Glide加载依旧是原来的图片问题
typescript26 - literal types
Selenium: form switching
Challenge 52 days to memorize Peppa Pig (Day 01)
Use controls as brushes to get bitmap code records
leetcode43 字符串相乘
Risk strategy important steps of tuning method
A,H,K,N
Immutable
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate