Skip to content

Instantly share code, notes, and snippets.

@1119-2916
Created January 30, 2017 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1119-2916/fe2eb72ec63f97a8b488d6243265dd4f to your computer and use it in GitHub Desktop.
Save 1119-2916/fe2eb72ec63f97a8b488d6243265dd4f to your computer and use it in GitHub Desktop.
AOJ
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
signed main()
{
Int(n);
Int(k);
Int(m);
while (n) {
queue<int> q;
For(i, m, n+1) {
q.push(i);
}
Rep(i, m) {
q.push(i);
}
q.pop();
while (q.size() != 1) {
Rep(i, k) {
int tmp = q.front();
q.pop();
q.push(tmp);
}
q.pop();
}
cout << q.front() << endl;
cin >> n >> k >> m;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment