约瑟夫环问题,只不过每次删除一个后,在移m的倍数。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
int N,k,m;
while(cin>>N>>k>>m && (N && k && m)){
int ans=;
for(int i=;i<=N-;i++){
ans=(ans+k)%i;
}
cout<<((ans+m)%N+)<<endl;
}
return ;
}

简单介绍一下约瑟夫问题

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1073

#include<iostream>
#include<queue>
using namespace std;
int main()
{
int N,k;
while(cin>>N>>k){
int ans=;
for(int i=;i<=N;i++){
ans=(ans+k)%i;
}
cout<<ans+<<endl;
}
return ;
}

最新文章

  1. Gridview中几个Button的应用
  2. mstsc 远程序桌面登录的 c#开发
  3. ASP通过ADODB读取Access数据库
  4. cxf的soap风格+spirng4+maven 服务端
  5. Fragment之间的通信
  6. Ubuntu 14.04 安装nVidia驱动后不能进入图形界面的恢复过程
  7. maven项目导入报错
  8. 判断DataReader中是否有指定列
  9. 【转】Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
  10. 【服务器运维】Windows Server 2008 R2 下配置证书服务器和HTTPS
  11. 水务新、老营收系统大PK
  12. java中常用的包、类、以及包中常用的类、方法、属性----sql和text\swing
  13. charls 抓包
  14. mysql针对单个库进行备份
  15. 一加3刷不了官方recoery
  16. An internal error occurred during: &amp;quot;Building workspace&amp;quot;. GC overhead limit exceeded
  17. C#数字类型输出字符串时保留指定小数位数的方法
  18. Solr服务在Linux上的搭建详细教程
  19. rtx自定义面板不更新
  20. iOS开发之int,NSInteger,NSUInteger,NSNumber的使用

热门文章

  1. C++容器(五):set类型
  2. reactor模式与java nio
  3. 设计模式之Mediator模式(笔记)
  4. JAVA学习第二十七课(多线程(六))- 多生产者多消费者问题(JDK1.5新特性)
  5. Effective JavaScript Item 49 对于数组遍历,优先使用for循环,而不是for..in循环
  6. 小米净水器与小区过滤价格水对照.xls
  7. 2013亚洲区域赛长沙站 ZOJ 3732 Graph Reconstruction
  8. js实现图片上传后即时预览
  9. sql笔试题-1
  10. Linux下通过rdesktop连接Windows远程桌面