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

      思考: 多思考, 多动脑。

  • 相关阅读:
    Linux 常用命令
    去除重叠区间
    Python 小工具之大文件去重
    有趣的pyfiglet
    杨辉三角
    Paginator分页
    Linux用户和用户组
    Grub介绍
    Linux系统运行级别
    Linux系统启动流程
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7236285.html
Copyright © 2011-2022 走看看