当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Excel record of integer programming optimization model to solve the problem
About making a progress bar for software initialization for Qt
使用string 容器翻转 字母
程序员代码面试指南 CD15 生成窗口最大值数组
Selenium: Manipulating Cookies
I met a shell script
2022年超全的Android面经(附含面试题|进阶资料)
Power button (LeetCode) 212. The word search II (2022.07.31)
USB3.0:VL817Q7-C0的LAYOUT指南(二)
Robot_Framework:常用内置关键字
随机推荐
Selenium: form switching
Selenium: Dropdown Box Actions
用位运算为你的程序加速
MySQL-Data Definition Language-DDLdatebase define language
About making a progress bar for software initialization for Qt
Selenium:弹窗处理
【MySQL必知必会】 表的优化 | 充分利用系统资源
Selenium: mouse, keyboard events
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
华为Android开发面试后得出的面试秘诀
请求/响应拦截器写法
Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
Use controls as brushes to get bitmap code records
PAT乙级 1001 害死人不偿命的(3n+1)猜想
Selenium:下拉框操作
matplotlib pyplot
Selenium: Popup Handling
ApiFile
Selenium: Introduction
挑战52天背完小猪佩奇(第01天)