From 90f20f9fd075e8967d02baf7554fcf24f4ae089c Mon Sep 17 00:00:00 2001 From: Vlad Utkin Date: Sat, 7 Oct 2017 18:43:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=B8=D0=BD=D1=83=D0=BB=20?= =?UTF-8?q?=D0=B5=D1=89=D1=91=20=D0=BC=D1=83=D1=81=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=98=D0=BD=D1=82=D0=B5=D0=BB=D0=BB=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0,=20=D0=BD=D0=B0=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uts/uts_17_aut_py/3/A_RUSH.py | 5 +- uts/uts_17_aut_py/4/A.py | 9 ++ uts/uts_17_aut_py/4/B.py | 9 ++ uts/uts_17_aut_py/4/C.py | 6 ++ uts/uts_17_aut_py/FoxNewBot/main.py | 47 ++++++++++ uts/uts_17_aut_py/FoxNewBot/requirements.txt | 2 + uts/uts_17_aut_py/lal/i-v3.py | 13 +++ uts/uts_2017_aut_cpp/A.cpp | 82 +++++++++++++++++ uts/uts_2017_aut_cpp/B.cpp | 78 +++++++++++++++++ uts/uts_2017_aut_cpp/C.cpp | 68 +++++++++++++++ uts/uts_2017_aut_cpp/D.cpp | 70 +++++++++++++++ uts/uts_2017_aut_cpp/E.cpp | 69 +++++++++++++++ uts/uts_2017_aut_cpp/F.cpp | 92 ++++++++++++++++++++ uts/uts_2017_aut_cpp/G.cpp | 78 +++++++++++++++++ uts/uts_2017_aut_cpp/H.cpp | 72 +++++++++++++++ uts/uts_2017_aut_cpp/main-1.cpp | 0 uts/uts_2017_aut_cpp/main.cpp | 65 +++++++------- 17 files changed, 732 insertions(+), 33 deletions(-) create mode 100644 uts/uts_17_aut_py/4/A.py create mode 100644 uts/uts_17_aut_py/4/B.py create mode 100644 uts/uts_17_aut_py/4/C.py create mode 100644 uts/uts_17_aut_py/FoxNewBot/main.py create mode 100644 uts/uts_17_aut_py/FoxNewBot/requirements.txt create mode 100644 uts/uts_17_aut_py/lal/i-v3.py create mode 100644 uts/uts_2017_aut_cpp/A.cpp create mode 100644 uts/uts_2017_aut_cpp/B.cpp create mode 100644 uts/uts_2017_aut_cpp/C.cpp create mode 100644 uts/uts_2017_aut_cpp/D.cpp create mode 100644 uts/uts_2017_aut_cpp/E.cpp create mode 100644 uts/uts_2017_aut_cpp/F.cpp create mode 100644 uts/uts_2017_aut_cpp/G.cpp create mode 100644 uts/uts_2017_aut_cpp/H.cpp create mode 100644 uts/uts_2017_aut_cpp/main-1.cpp diff --git a/uts/uts_17_aut_py/3/A_RUSH.py b/uts/uts_17_aut_py/3/A_RUSH.py index 37d37ab..0b3365f 100644 --- a/uts/uts_17_aut_py/3/A_RUSH.py +++ b/uts/uts_17_aut_py/3/A_RUSH.py @@ -3,7 +3,7 @@ import zlib, json #n = int(input()) # Лучше не смотреть на это НЕ решение) #pool = list(map(int, input().split())) #ans = sum(pool)//2 -dis = { +'''dis = { 206: 207, 155: 156, 355: 360, @@ -13,6 +13,9 @@ dis = { 464: 465, 54: 103, 311: 343 +}''' +dis = { + } print(json.dumps(dis)) print(json.loads(json.dumps(dis))) diff --git a/uts/uts_17_aut_py/4/A.py b/uts/uts_17_aut_py/4/A.py new file mode 100644 index 0000000..8892da3 --- /dev/null +++ b/uts/uts_17_aut_py/4/A.py @@ -0,0 +1,9 @@ +n, k, x = list(map(int, input().split())) +from itertools import combinations_with_replacement +cnt = 0 +for i in combinations_with_replacement(range(1, n+1), k): + if cnt == x: + for j in i: + print(j, end=' ') + break + cnt += 1 diff --git a/uts/uts_17_aut_py/4/B.py b/uts/uts_17_aut_py/4/B.py new file mode 100644 index 0000000..42ceaa4 --- /dev/null +++ b/uts/uts_17_aut_py/4/B.py @@ -0,0 +1,9 @@ +n, k = list(map(int, input().split())) +find = tuple(map(int, input().split())) +from itertools import combinations_with_replacement +cnt = 0 +for i in combinations_with_replacement(range(1, n+1), k): + if i == find: + print(cnt) + break + cnt += 1 diff --git a/uts/uts_17_aut_py/4/C.py b/uts/uts_17_aut_py/4/C.py new file mode 100644 index 0000000..b80bda2 --- /dev/null +++ b/uts/uts_17_aut_py/4/C.py @@ -0,0 +1,6 @@ +le, de = list(map(int, input().split())) +de = bin(de)[2:] +if len(de) < le: + de = ('0'*(le - len(de))) + de + +print(de) diff --git a/uts/uts_17_aut_py/FoxNewBot/main.py b/uts/uts_17_aut_py/FoxNewBot/main.py new file mode 100644 index 0000000..7d4db0c --- /dev/null +++ b/uts/uts_17_aut_py/FoxNewBot/main.py @@ -0,0 +1,47 @@ +from telegram.ext import Updater +updater = Updater(token='462381555:AAGpyrfrkxt0_uitj-z4ZFUMDMfQt0MdZhY') + +dispatcher = updater.dispatcher +import sqlite3 +database_connector = sqlite3.connect +DATABASE = 'sq.sql' +import logging +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.INFO) + + +def start(bot, update): + conn = database_connector(DATABASE) + conn.execute('INSERT INTO Users VALUES (:user_id, :us)', {"user_id": update.message.chat_id, "us": 'User'}) + conn.commit() + conn.close() + bot.send_message(chat_id=update.message.chat_id, text="Вы успешно подписались на новости Лисьего Носа!") + print(update.message.chat_id) + +DEBUG = True +def send(bot, update): + if update.message.chat_id != 130703270: + return + conn = database_connector(DATABASE) + cursor = conn.cursor() + cursor.execute('SELECT user_id FROM Users') + for i in cursor.fetchall(): + if DEBUG: + bot.send_message(chat_id=int(i[0]), text=update.message.text[5:]) + else: + bot.send_message(chat_id=130703270, text=update.message.text[5:]) + conn.close() + print('yes') + +def kot(bot, update): + bot.send_message(chat_id=update.message.chat_id, photo=open('test.png', 'rb')) + +from telegram.ext import CommandHandler + +start_handler = CommandHandler('start', start) + +dispatcher.add_handler(start_handler) +dispatcher.add_handler(CommandHandler('send', send)) +dispatcher.add_handler(CommandHandler('kot', kot)) + +updater.start_polling() diff --git a/uts/uts_17_aut_py/FoxNewBot/requirements.txt b/uts/uts_17_aut_py/FoxNewBot/requirements.txt new file mode 100644 index 0000000..44d99d1 --- /dev/null +++ b/uts/uts_17_aut_py/FoxNewBot/requirements.txt @@ -0,0 +1,2 @@ + python-telegram-bot + diff --git a/uts/uts_17_aut_py/lal/i-v3.py b/uts/uts_17_aut_py/lal/i-v3.py new file mode 100644 index 0000000..97cfb03 --- /dev/null +++ b/uts/uts_17_aut_py/lal/i-v3.py @@ -0,0 +1,13 @@ +import math + +n = 10000000 + +a = [True] * n + +for i in range(2, int(math.sqrt(n))): + for j in range(i * 2, n, i): + a[j] = False +b = [i for i in range(2, n) if a[i]] + +#print(b) +print(len(b)) diff --git a/uts/uts_2017_aut_cpp/A.cpp b/uts/uts_2017_aut_cpp/A.cpp new file mode 100644 index 0000000..133b8e5 --- /dev/null +++ b/uts/uts_2017_aut_cpp/A.cpp @@ -0,0 +1,82 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +//////////////////////////////////////////////////////////////////////////////////////////////// + +ll n, k, x; +ll a[35]; +ll dp[35][35]; + +int main() { + cin >> n >> k >> x; + + forin(i, 1, 35) { + dp[1][i] = 1; + } + + for (int i = 2; i <= k; ++i) { + for (int j = 1; j <= n; ++j) { + for (int k = j; k <= n; ++k) { + dp[i][j] += dp[i - 1][k]; + } + } + } + + if (n == 1) { + cout << 1 << endl; + return 0; + } + + a[0] = 1; + + + forin(i, 1, k + 1) { + for (int val = a[i - 1]; val <= n; ++val) { + // cout << x << " " << val << " " << dp[k - i + 1][val] << endl; + if (x < dp[k - i + 1][val]) { + a[i] = val; + break; + } else { + x -= dp[k - i + 1][val]; + } + } + } + + forin(i, 1, k + 1) { + cout << a[i] << " "; + } + cout << endl; + return 0; +} diff --git a/uts/uts_2017_aut_cpp/B.cpp b/uts/uts_2017_aut_cpp/B.cpp new file mode 100644 index 0000000..3475aed --- /dev/null +++ b/uts/uts_2017_aut_cpp/B.cpp @@ -0,0 +1,78 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +//////////////////////////////////////////////////////////////////////////////////////////////// + +ll n, k, x; +ll a[35]; +ll dp[35][35]; + +int main() { + cin >> n >> k; + + forin(i, 1, k + 1) { + cin >> a[i]; + } + + forin(i, 1, 35) { + dp[1][i] = 1; + } + + for (int i = 2; i <= k; ++i) { + for (int j = 1; j <= n; ++j) { + for (int q = j; q <= n; ++q) { + dp[i][j] += dp[i - 1][q]; + } + } + } + + if (n == 1) { + cout << 0 << endl; + return 0; + } + + a[0] = 1; + + + forin(i, 1, k + 1) { + for (int val = a[i - 1]; val < a[i]; ++val) { + // cout << i + 1 << " " << val << " " << dp[k - i - 1][val] << endl; + x += dp[k - i + 1][val]; + } + } + + cout << x << endl; + return 0; +} \ No newline at end of file diff --git a/uts/uts_2017_aut_cpp/C.cpp b/uts/uts_2017_aut_cpp/C.cpp new file mode 100644 index 0000000..cc83927 --- /dev/null +++ b/uts/uts_2017_aut_cpp/C.cpp @@ -0,0 +1,68 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +//////////////////////////////////////////////////////////////////////////////////////////////// + +const int MAXN = 50; +ll n, k; +ll dp[MAXN][2]; +int a[MAXN]; + +int main() { + cin >> n >> k; + + dp[1][0] = 1; + dp[1][1] = 1; + + forin(i, 2, 50) { + dp[i][0] = dp[i - 1][0] + dp[i - 1][1]; + dp[i][1] = dp[i - 1][0]; + } + + rep(i, n) { + if (dp[n - i][0] > k) { + a[i] = 0; + } else { + k -= dp[n - i][0]; + a[i] = 1; + } + } + + rep(i, n) { + cout << a[i]; + } + cout << endl; + return 0; +} diff --git a/uts/uts_2017_aut_cpp/D.cpp b/uts/uts_2017_aut_cpp/D.cpp new file mode 100644 index 0000000..d8b0962 --- /dev/null +++ b/uts/uts_2017_aut_cpp/D.cpp @@ -0,0 +1,70 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +//////////////////////////////////////////////////////////////////////////////////////////////// + +const int MAXN = 100; + +ll n, k, bal; +ll dp[MAXN][MAXN]; +string res; + +int main() { + cin >> n >> k; + n *= 2; + + dp[0][0] = 1; + for (int i = 1; i < 100; ++i) { + for (int j = 1; j < 100; ++j) { + dp[i][j] += dp[i - 1][j - 1]; + } + for (int j = 0; j < 99; ++j) { + dp[i][j] += dp[i - 1][j + 1]; + } + } + + rep(i, n) { + if (k < dp[n - i - 1][bal + 1]) { + bal++; + res.push_back('('); + } else { + k -= dp[n - i - 1][bal + 1]; + bal--; + res.push_back(')'); + } + } + cout << res << endl; + return 0; +} \ No newline at end of file diff --git a/uts/uts_2017_aut_cpp/E.cpp b/uts/uts_2017_aut_cpp/E.cpp new file mode 100644 index 0000000..4a22e4c --- /dev/null +++ b/uts/uts_2017_aut_cpp/E.cpp @@ -0,0 +1,69 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +//////////////////////////////////////////////////////////////////////////////////////////////// + +const int MAXN = 100; + +ll n, bal; +ll dp[MAXN][MAXN]; +string s; +ll res; + +int main() { + cin >> n >> s; + n *= 2; + + dp[0][0] = 1; + for (int i = 1; i < 100; ++i) { + for (int j = 1; j < 100; ++j) { + dp[i][j] += dp[i - 1][j - 1]; + } + for (int j = 0; j < 99; ++j) { + dp[i][j] += dp[i - 1][j + 1]; + } + } + + rep(i, n) { + if (s[i] == '(') { + bal++; + } else { + res += dp[n - i - 1][bal + 1]; + bal--; + } + } + cout << res << endl; + return 0; +} diff --git a/uts/uts_2017_aut_cpp/F.cpp b/uts/uts_2017_aut_cpp/F.cpp new file mode 100644 index 0000000..9abc718 --- /dev/null +++ b/uts/uts_2017_aut_cpp/F.cpp @@ -0,0 +1,92 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() +#define log(x) cout << #x << " = " << x << endl; + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +template T fact(T n) {if (n == 1) return 1; return n * fact(n - 1);} +//////////////////////////////////////////////////////////////////////////////////////////////// + +const int MAXN = 105; +ll n, k; +ll dp[MAXN][MAXN]; // dp[sum][first_digit] +vector res; + +int main() { + cin >> n >> k; + + for (int i = 1; i < 105; ++i) { // sum + for (int j = 1; j < i; ++j) { // first digit + for (int k = j; k < 105; ++k) { // second digit + dp[i][j] += dp[i - j][k]; + } + } + dp[i][i] = 1; + } + + if (n == 0 && k != 0) { + cout << "N/A" << endl; + return 0; + } + + ll sm = 0; + for (int i = 1; i <= n; ++i) { + sm += dp[n][i]; + } + if (k >= sm && n != 0) { + cout << "N/A" << endl; + return 0; + } + + ll last = 1; + + while (n) { + for (int i = last; i <= n; ++i) { + // cout << "dp[" << n << "][" << i << "] = " << dp[n][i] << endl; + if (k < dp[n][i]) { + n -= i; + res.push_back(i); + last = i; + break; + } else { + k -= dp[n][i]; + } + } + } + cout << sz(res) << endl; + rep(i, sz(res)) { + cout << res[i] << " "; + } + cout << endl; + return 0; +} \ No newline at end of file diff --git a/uts/uts_2017_aut_cpp/G.cpp b/uts/uts_2017_aut_cpp/G.cpp new file mode 100644 index 0000000..820b4db --- /dev/null +++ b/uts/uts_2017_aut_cpp/G.cpp @@ -0,0 +1,78 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) {if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a;} +template T fact(T n) {if (n == 1) return 1; return n * fact(n - 1);} +//////////////////////////////////////////////////////////////////////////////////////////////// + +ll n, k; + +vector res; +vector not_used; + +int main() { + cin >> n >> k; + if (k > fact(n) || k <= 0) { + cout << "INVALID number." << endl; + return 0; + } + k--; + if (n == 1) { + cout << 1 << endl; + return 0; + } + + for (int i = 1; i <= n; ++i) { + not_used.push_back(i); + } + ll size = fact(n - 1); + rep(i, n) { + ll cnt = k / size; + if (cnt > sz(not_used)) { + cnt = sz(not_used) - 1; + } + res.push_back(not_used[cnt]); + not_used.erase(not_used.begin() + cnt); + k %= size; + if (i != n - 1) { + size = size / (n - i - 1); + } + } + + rep(i, n) { + cout << res[i] << " "; + } + cout << endl; + return 0; +} \ No newline at end of file diff --git a/uts/uts_2017_aut_cpp/H.cpp b/uts/uts_2017_aut_cpp/H.cpp new file mode 100644 index 0000000..f492d1b --- /dev/null +++ b/uts/uts_2017_aut_cpp/H.cpp @@ -0,0 +1,72 @@ + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Andrey Odintsov +#include +using namespace std; + +#define mp make_pair +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0) +#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) +#define sz(x) ((int)((x).size())) +#define len(x) ((int)((x).length())) +#define x first +#define y second +#define foreach(it, v) for (auto it : v) +#define rep(it, n) for (int it = 0; it < n; ++it) +#define forin(it, l, r) for (int it = l; it < r; ++it) +#define all(x) x.begin(), x.end() + +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +const int INF = (1 << 31) - 1; +const ll LINF = (1ll << 63) - 1; +const double DINF = numeric_limits::infinity(); +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } +mt19937 mmtw(MOD); +ll rnd(ll x, ll y) { static uniform_int_distribution d; return d(mmtw) % (y - x + 1) + x; } +template T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; } +template T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; } +template T binpow(T n, T k) { if (k == 1) return n; if (k & 1) return binpow(n, k - 1) * n; T a = binpow(n, k / 2); return a * a; } +template T fact(T n) { if (n == 1) return 1; return n * fact(n - 1); } +//////////////////////////////////////////////////////////////////////////////////////////////// + +const int MAXN = 25; +ll n; +ll a[MAXN]; +ll res; +vector not_used; + +int main() { + cin >> n; + rep(i, n) { + cin >> a[i]; + } + + if (n == 1) { + cout << 1 << endl; + return 0; + } + + for (int i = 1; i <= n; ++i) { + not_used.push_back(i); + } + + ll size = fact(n - 1); + rep(i, n) { + auto it = find(all(not_used), a[i]); + res += size * (it - not_used.begin()); + not_used.erase(it); + if (i != n - 1) { + size = size / (n - i - 1); + } + } + + cout << res + 1 << endl; + return 0; +} \ No newline at end of file diff --git a/uts/uts_2017_aut_cpp/main-1.cpp b/uts/uts_2017_aut_cpp/main-1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/uts/uts_2017_aut_cpp/main.cpp b/uts/uts_2017_aut_cpp/main.cpp index 1a69439..1ec4cd4 100644 --- a/uts/uts_2017_aut_cpp/main.cpp +++ b/uts/uts_2017_aut_cpp/main.cpp @@ -1,48 +1,49 @@ +#include #include +#include #include +#include using namespace std; +void comb(unsigned int N, unsigned int K, unsigned int stp) +{ + string bitmask(K, 1); + bitmask.resize((unsigned long)N, 0); + unsigned int carl = 0; + do { + for (int i = 0; i < N; ++i) + { + if (bitmask[i]) { cout << " " << i; } + } + cout << endl; + carl++; + } while (prev_permutation(bitmask.begin(), bitmask.end())); +} + int compare(const void * x1, const void * x2) { return ( *(int*)x1 - *(int*)x2 ); } int main() { - unsigned long long n, b, p; - cin >> n >> b >> p; - unsigned long long a[n]; - for (long i = 0; i < n; i++) { - a[i] = (unsigned long long)pow(b, i+1) % p; + unsigned long long n, na; + //cin >> n; + for (na = 1; na < 101; na++) { + n = na; + cout << na << ':' << '\n'; + if(n==1){ + cout << 1; + //return 0; } - unsigned long long ma; - unsigned long long mi; - long lastclean; - for (long j = 0; j < n-1; j++) { - mi = 10000000000; - ma = 0; - for (long i = 0; i < n; i++) { - bool change = false; - if (a[i] >= ma && a[i] != 10000000000) { - ma = a[i]; - change = true; - lastclean = i; - } - if (a[i] <= mi && a[i] != 10000000000) { - mi = a[i]; - change = true; - lastclean = i; - } - if (change) { - a[i] = 10000000000; - } + for (unsigned long long i = 2; i*i <= n; i++) { + while (n % i == 0) { + cout << i << ' '; + n = n / i; } - a[lastclean] = (mi + ma) % p; - cout << a[lastclean] << ' '; } - //cout << '\n'; - //for (long i = 0; i < n; i++) { - // cout << a[i] << ' '; - //} + if (n != 1) { + cout << n << ' '; + } cout << '\n'; } return 0; }