-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6572376
commit eda446d
Showing
9 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <bits/stdc++.h> | ||
#define fi first | ||
#define se second | ||
#define pb push_back | ||
#define mp make_pair | ||
#define MOD 1000000007 | ||
#define INF 1234567890 | ||
#define pii pair<int,int> | ||
#define LL long long | ||
using namespace std; | ||
|
||
int main () { | ||
//clock_t start = clock(); | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
int tc; | ||
cin >> tc; | ||
while (tc--) { | ||
LL n, k; | ||
cin >> n >> k; | ||
LL l = 0, h = 2000000000, ans = 0; | ||
while (l <= h) { | ||
LL m = (l + h) / 2; | ||
if ((m - (m / n)) == k) { | ||
if (m % n > 0) { | ||
ans = m; | ||
break; | ||
} else { | ||
h = m-1; | ||
} | ||
} else if ((m - (m / n)) > k) { | ||
h = m-1; | ||
} else { | ||
l = m+1; | ||
} | ||
} | ||
cout << ans << endl; | ||
} | ||
//cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Author : Morgen Sudyanto | ||
* Problem : Menghitung Buku | ||
*/ | ||
|
||
// problem source: https://codeforces.com/contest/1352/problem/C | ||
|
||
#include <bits/stdc++.h> | ||
#define fi first | ||
#define se second | ||
#define pb push_back | ||
#define mp make_pair | ||
#define MOD 1000000007 | ||
#define INF 1234567890 | ||
#define pii pair<int,int> | ||
#define LL long long | ||
using namespace std; | ||
|
||
int main () { | ||
//clock_t start = clock(); | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
int tc; | ||
cin >> tc; | ||
while (tc--) { | ||
int n, k; | ||
cin >> n >> k; | ||
int ans = (k / (n-1)) * n + (k % (n-1)); | ||
if ((k % (n-1)) == 0) ans--; | ||
cout << ans << endl; | ||
} | ||
//cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <tcframe/spec.hpp> | ||
using namespace tcframe; | ||
|
||
class ProblemSpec : public BaseProblemSpec { | ||
private: | ||
bool eachElementBetween(const vector<int>& X, int lo, int hi) { | ||
for (int x : X) { | ||
if (x < lo || x > hi) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
protected: | ||
int T; | ||
vector<int> N, K; | ||
vector<int> sum; | ||
|
||
void InputFormat() { | ||
LINE(T); | ||
LINES(N, K) % SIZE(T); | ||
} | ||
|
||
void OutputFormat() { | ||
LINES(sum) % SIZE(T); | ||
} | ||
|
||
void GradingConfig() { | ||
TimeLimit(1); | ||
MemoryLimit(256); | ||
} | ||
|
||
void Constraints() { | ||
CONS(1 <= T && T <= 1000); | ||
CONS(eachElementBetween(N, 2, 1000000000)); | ||
CONS(eachElementBetween(K, 1, 1000000000)); | ||
} | ||
}; | ||
|
||
class TestSpec : public BaseTestSpec<ProblemSpec> { | ||
protected: | ||
void SampleTestCase1() { | ||
Input({ | ||
"5", | ||
"7 4", | ||
"4 7", | ||
"2 100", | ||
"5 12", | ||
"500000000 1000000000" | ||
}); | ||
Output({ | ||
"4", | ||
"9", | ||
"199", | ||
"14", | ||
"1000000002" | ||
}); | ||
} | ||
|
||
void TestCases() { | ||
vector<int> N1, K1; | ||
// random | ||
for (int i=1;i<=500;i++) { | ||
N1.push_back(rnd.nextInt(2, 1000)); | ||
K1.push_back(rnd.nextInt(1, 1000)); | ||
} | ||
|
||
// n < k | ||
for (int i=1;i<=500;i++) { | ||
int tn = rnd.nextInt(2, 1000), tk = rnd.nextInt(1, 1000); | ||
tn %= tk; | ||
if (tn < 2) tn += 2; | ||
N1.push_back(tn); | ||
K1.push_back(tk); | ||
} | ||
CASE(T = 1000, N = N1, K = K1); | ||
|
||
vector<int> N2, K2; | ||
// random | ||
for (int i=1;i<=500;i++) { | ||
N2.push_back(rnd.nextInt(2, 1000000000)); | ||
K2.push_back(rnd.nextInt(1, 1000000000)); | ||
} | ||
|
||
// n < k | ||
for (int i=1;i<=500;i++) { | ||
int tn = rnd.nextInt(2, 1000000000), tk = rnd.nextInt(1, 1000000000); | ||
tn %= tk; | ||
if (tn < 2) tn += 2; | ||
N2.push_back(tn); | ||
K2.push_back(tk); | ||
} | ||
CASE(T = 1000, N = N2, K = K2); | ||
} | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
\documentclass{article} | ||
|
||
\usepackage{geometry} | ||
\usepackage{amsmath} | ||
\usepackage{graphicx} | ||
\usepackage{listings} | ||
\usepackage{hyperref} | ||
\usepackage{multicol} | ||
\usepackage{fancyhdr} | ||
\pagestyle{fancy} | ||
\hypersetup{ colorlinks=true, linkcolor=black, filecolor=magenta, urlcolor=cyan} | ||
\geometry{ a4paper, total={170mm,257mm}, top=20mm, right=20mm, bottom=20mm, left=20mm} | ||
\setlength{\parindent}{0pt} | ||
\setlength{\parskip}{1em} | ||
\renewcommand{\headrulewidth}{0pt} | ||
\lhead{ITB - IEEEXtreme 14.0 Selection} | ||
\fancyfoot[CE,CO]{\thepage} | ||
\lstset{ | ||
basicstyle=\ttfamily\small, | ||
columns=fixed, | ||
extendedchars=true, | ||
breaklines=true, | ||
tabsize=2, | ||
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, | ||
frame=none, | ||
showtabs=false, | ||
showspaces=false, | ||
showstringspaces=false, | ||
prebreak={}, | ||
keywordstyle=\color[rgb]{0.627,0.126,0.941}, | ||
commentstyle=\color[rgb]{0.133,0.545,0.133}, | ||
stringstyle=\color[rgb]{01,0,0}, | ||
captionpos=t, | ||
escapeinside={(\%}{\%)} | ||
} | ||
|
||
\begin{document} | ||
|
||
\begin{center} | ||
\section*{I. Menghitung Buku} | ||
|
||
\begin{tabular}{ | c c | } | ||
\hline | ||
Batas Waktu & 1s \\ % jangan lupa ganti time limit | ||
Batas Memori & 256MB \\ % jangan lupa ganti memory limit | ||
\hline | ||
\end{tabular} | ||
\end{center} | ||
|
||
\subsection*{Deskripsi} | ||
|
||
Hasan adalah seorang mahasiswa ITB yang sangat rajin. Dia memiliki buku yang bernomor $1, 2, 3, \dots$ sampai tak terhingga. Kamal, temannya Hasan, mengambil semua buku - buku yang memiliki nomor berkelipatan $N$. Sekarang Hasan penasaran, ia ingin menghitung apa nomor yang ada di buku pada urutan ke $K$. | ||
|
||
Misalnya, jika $N$ bernilai $4$ dan $K$ bernilai $7$, maka barisannya adalah $1, 2, 3, 5, 6, 7, 9, 10, 11, \dots$ dan buku yang berada pada urutan ke $7$ adalah buku bernomor $9$. | ||
|
||
\subsection*{Format Masukan} | ||
|
||
Baris pertama terdiri dari satu bilangan bulat positif $T$ ($1 \leq T \leq 1000$), menyatakan banyaknya kasus uji. | ||
|
||
$T$ Baris berikutnya berisi $2$ buah bilangan $N$ ($2 \leq N \leq 10^9$) dan $K$ ($2 \leq K \leq 10^9$). | ||
|
||
\subsection*{Format Keluaran} | ||
|
||
Keluarkan $T$ buah baris yang berisi jawaban untuk setiap kasus uji. | ||
\\ | ||
|
||
\begin{multicols}{2} | ||
\subsection*{Contoh Masukan} | ||
\begin{lstlisting} | ||
5 | ||
7 4 | ||
4 7 | ||
2 100 | ||
5 12 | ||
500000000 1000000000 | ||
\end{lstlisting} | ||
\columnbreak | ||
\subsection*{Contoh Keluaran} | ||
\begin{lstlisting} | ||
4 | ||
9 | ||
199 | ||
14 | ||
1000000002 | ||
\end{lstlisting} | ||
\vfill | ||
\null | ||
\end{multicols} | ||
|
||
\subsection*{Penjelasan} | ||
Untuk kasus pertama, barisannya adalah $1, 2, 3, 4, 5, 6, 8, 9, \dots$. Dapat dilihat bahwa buku ke-$4$ adalah buku bernomor $4$. | ||
|
||
Kasus kedua telah dijelaskan di deskripsi soal. | ||
|
||
\pagebreak | ||
|
||
\end{document} |
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters