HDU

题意:有n双袜子,编号1到n,放在衣柜里,每天早晨取衣柜中编号最小的袜子穿,晚上将这双袜子放在篮子里,当篮子里有n-1双袜子时,清洗袜子,直到第二天晚上才洗好,并将洗好的袜子重新放回衣柜。

分析:规律为

1、n=2时,1 2 1 2 1 2 1 2……

2、n=3时,1 2 3 1 2 1 3 1 2 1 3……

3、n=4时,1 2 3 4 1 2 3 1 2 4 1 2 3 1 2 4……

4、n=5时,1 2 3 4 5 1 2 3 4 1 2 3 5 1 2 3 4 1 2 3 5……

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
    LL n, k;
    int kase = 0;
    while(scanf("%lld%lld", &n, &k) == 2){
        printf("Case #%d: ", ++kase);
        if(k <= n){
            printf("%lld
", k);
            continue;
        }
        LL a = (k - n) / (n - 1);
        LL b = (k - n) % (n - 1);
        if(b != 0){
            printf("%lld
", b);
        }
        else{
            if(a & 1){
                printf("%lld
", n - 1);
            }
            else{
                printf("%lld
", n);
            }
        }
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7236355.html