Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A自我感觉良好

Posted by Time_Limite_Error at 2019-12-31 11:10:37 on Problem 2156
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <stdio.h>
#include <fstream>
#include <map>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream cin("input.txt");
//    ofstream cout("output.txt");
    int N, M, K, J;
    cin>>N>>M>>K>>J;
    int ans=0;
    M %= (N+1);
    int f = 0;
    // 倒数c-1次的位置为0,往后推到最后一次,得到相对于n的位置。
    for(int i=0; i < K ; i++) {
        f = (f + M) % (N + 2 - K + i);
        if(f==0) f = N + 2 - K + i;
    }
    // 往前倒推,更新j的位置,找到消除j的迭代次数。
    while(J != M) {
        ans ++;
        N--;
        if(M < J) {
            J = J - M;
        } else {
            J = N + 1 - (M - J - 1) ;
        }
    }
    cout<<f<<" "<<ans+1<<endl;
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator