当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
使用string 容器翻转 字母
typescript24 - type inference
The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
2022年湖南工学院ACM集训第六次周测题解
y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
Robot_Framework: commonly used built-in keywords
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询
随机推荐
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
Pyspark Machine Learning: Vectors and Common Operations
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
2022年湖南工学院ACM集训第六次周测题解
pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)
Selenium: upload and download files
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
用控件当画笔获得bitmap代码记录
What should I do if the neural network cannot be trained?
Power button (LeetCode) 212. The word search II (2022.07.31)
Robot_Framework: Assertion
Hunan institute of technology in 2022 ACM training sixth week antithesis
(2022牛客多校四)K-NIO‘s Sword(思维)
Selenium:浏览器操作
Challenge 52 days to memorize Peppa Pig (Day 01)
LeetCode 27. 移除元素
Selenium: Manipulating Cookies