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

     
    KazaQ wears socks everyday. 

    At the beginning, he has nn pairs of socks numbered from 11 to nn in his closets. 

    Every morning, he puts on a pair of socks which has the smallest number in the closets. 

    Every evening, he puts this pair of socks in the basket. If there are n1n−1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening. 

    KazaQ would like to know which pair of socks he should wear on the kk-th day.

    InputThe input consists of multiple test cases. (about 20002000) 

    For each case, there is a line contains two numbers n,kn,k (2n109,1k1018)(2≤n≤109,1≤k≤1018).
    OutputFor each test case, output " Case #xx: yy" in one line (without quotes), where xxindicates the case number starting from 11 and yy denotes the answer of corresponding case.Sample Input

    3 7
    3 6
    4 9

    Sample Output

    Case #1: 3
    Case #2: 1
    Case #3: 2

    分析找规律
    会有状态循环:
    从第一次取完后开始,每两次取完所有之后会开始重复


    代码
     1 #include <bits/stdc++.h>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <stack>
     5 #include <cstdlib>
     6 #include <queue>
     7 #include <cmath>
     8 #include <cstdio>
     9 #include <algorithm>
    10 #include <string>
    11 #include <vector>
    12 #include <list>
    13 #include <iterator>
    14 #include <set>
    15 #include <map>
    16 #include <utility>
    17 #include <iomanip>
    18 #include <ctime>
    19 #include <sstream>
    20 #include <bitset>
    21 #include <deque>
    22 #include <limits>
    23 #include <numeric>
    24 #include <functional>
    25 
    26 #define gc getchar()
    27 #define mem(a) memset(a,0,sizeof(a))
    28 #define mod 1000000007
    29 #define sort(a,n,int) sort(a,a+n,less<int>())
    30 #define fread() freopen("in.in","r",stdin)
    31 #define fwrite() freopen("out.out","w",stdout)
    32 using namespace std;
    33 
    34 typedef long long ll;
    35 typedef char ch;
    36 typedef double db;
    37 
    38 const int maxn=1e5+10;
    39 //ll a[maxn];
    40 int aa[maxn];
    41 
    42 int main()
    43 {
    44     ll m ,n;
    45     while(cin >> m >> n)
    46     if(n<=m)cout<<"Case #"<<t<<": "<<n<<endl;
    47     else
    48     {
    49         n -= m;
    50         n %= (2*m-2);
    51         if(!n)cout<<"Case #"<<t<<": "<<m<<endl;
    52         else
    53         {
    54             if(n<=m-1) cout<<"Case #"<<t<<": "<<n<<endl;
    55             else cout<<"Case #"<<t<<": "<<n-m+1<<endl;
    56         }
    57     }
    58     return 0;
    59 }

    作者:YukiRinLL

    出处:YukiRinLL的博客--https://www.cnblogs.com/SutsuharaYuki/

    您的支持是对博主最大的鼓励,感谢您的认真阅读。

    本文版权归作者所有,欢迎转载,但请保留该声明。

  • 相关阅读:
    socket的accept函数解析
    c socket(续)
    C socket指南
    网络字节序和本机字节序
    jar包
    RESTful API 设计指南[转]
    理解RESTful架构[转]
    c语言正则表达式
    Fedora设置中文
    创建框架结构的页面2
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/11225381.html
Copyright © 2011-2022 走看看