设为首页 加入收藏

TOP

HDU-4841 圆桌问题 STL模拟约瑟夫问题
2015-07-20 17:45:28 来源: 作者: 【 】 浏览:2
Tags:HDU-4841 圆桌 问题 STL 模拟 约瑟夫

中文题,题意一看就是卧槽,这不约瑟夫么,然后脑子一抽就用了链表写,然后果然T了,最后用Vector模拟的约瑟夫问题。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #define LL __int64 using namespace std; int n,m; vector
          
           p; int flag[55000]; int main() { int cnt; int s; while(scanf("%d%d",&n,&m)!=EOF) { s=2*n; p.clear(); for(int i=1;i<=s;i++) { p.push_back(i); flag[i]=0; } cnt=1; while(s>n) { cnt+=m-1; if(cnt<=s) { flag[p[cnt-1]]=1; p.erase(p.begin()+cnt-1); if(cnt==s) { cnt=1; } } else { cnt%=s; if(cnt==0) { cnt=s; } flag[p[cnt-1]]=1; p.erase(p.begin()+cnt-1); if(cnt==s) { cnt=1; } } s--; } for(int i=1;i<=2*n;i++) { if(flag[i]) { cout<<"B"; } else { cout<<"G"; } if(i%50==0) { cout<
           
            

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA100 The 3n + 1 problem 下一篇C++11 thread(1)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)
·Linux学习教程,Linu (2025-12-25 05:50:06)
·工业机器人TCP校准中 (2025-12-25 05:19:17)
·opc 通讯协议与 TCP (2025-12-25 05:19:15)