zoukankan      html  css  js  c++  java
  • HDU 6043 KazaQ's Socks 思维题

      题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6043

      题目大意: 有n个袜子从1到n编号, 每天都要穿干净的袜子中的标号最小的那个, 脏的袜子放进框里, 框里面有n-1个袜子时拿去清洗, 第二天又变成干净的袜子可以重新穿。问第K天穿的袜子的标号是多少?

      解题思路: 一道思维题, 顺次写出要穿的袜子的标号就可以找出循环节, 然后编程。

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    typedef long long ll;
    ll n, k;
    int cases = 0;
    int main() {
        while( cin >> n >> k ) {
            ll ans = -1;
            if( k <= n ) {
                ans = k;
            }
            else if( n == 2 ) {
                ans = k & 1 ? 1 : 2;
            }
            else {
                ll temp = k - n;
                ll temp1 = temp;
                temp %= (n-1);
                ans = temp;
                if( temp == 0 ) {
                    if( (temp1 / (n-1)) & 1 ) {
                        ans = n-1;
                    }
                    else {
                        ans = n;
                    }
                }
                
            }
            cout << "Case #" << ++cases << ": " << ans << endl;
        }
        return 0;
    }
    View Code

      思考: 多思考, 多动脑。

  • 相关阅读:
    多态
    封装
    继承
    面向对象
    2.机器学习相关数学基础
    作业1 机器学习概述
    作业15 语法制导的语义翻译
    作业14 算符优先分析
    作业13 自下而上语法分析
    作业12 实验二 递归下降语法分析
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7236285.html
Copyright © 2011-2022 走看看