hud 6043

题意:一开始有n双袜子放在柜子里,每天穿柜子里序号最小的,第二天把穿过的放到盒子里,当盒子里有n-1个,他会洗掉,然后第二天晚上放到柜子里

思路:规律,(1----n)(1-----n-2,n)(1-----n-2,n-1)(1-----n-2,n)(1-----n-2,n-1)(1-----n-2,n)(1-----n-2,n-1).......

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 
 5 int main(){
 6     ll n,m;
 7     int kk=1;
 8     while(scanf("%I64d%I64d",&n,&m)!=EOF){
 9         printf("Case #%d: ",kk++);
10         if(m<=n) printf("%I64d\n",m);
11         else {
12             m-=n;
13             n--;
14             ll k=m/n;
15             if(m%n!=0){
16                 k++;
17             }
18             if(k%2==0){
19                 if(m%n!=0) printf("%I64d\n",m%n);
20                 else printf("%I64d\n",n+1);
21             }
22             else {
23                 if(m%n!=0) printf("%I64d\n",m%n);
24                 else printf("%I64d\n",n);
25             }
26         }
27     }
28     return 0;
29 }

 

posted on 2017-07-26 09:41  hhhhx  阅读(95)  评论(0编辑  收藏  举报

导航