UVA And Then There Was One
2024-08-31 15:16:50
约瑟夫环问题,只不过每次删除一个后,在移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 ;
}
最新文章
- Gridview中几个Button的应用
- mstsc 远程序桌面登录的 c#开发
- ASP通过ADODB读取Access数据库
- cxf的soap风格+spirng4+maven 服务端
- Fragment之间的通信
- Ubuntu 14.04 安装nVidia驱动后不能进入图形界面的恢复过程
- maven项目导入报错
- 判断DataReader中是否有指定列
- 【转】Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
- 【服务器运维】Windows Server 2008 R2 下配置证书服务器和HTTPS
- 水务新、老营收系统大PK
- java中常用的包、类、以及包中常用的类、方法、属性----sql和text\swing
- charls 抓包
- mysql针对单个库进行备份
- 一加3刷不了官方recoery
- An internal error occurred during: &;quot;Building workspace&;quot;. GC overhead limit exceeded
- C#数字类型输出字符串时保留指定小数位数的方法
- Solr服务在Linux上的搭建详细教程
- rtx自定义面板不更新
- iOS开发之int,NSInteger,NSUInteger,NSNumber的使用
热门文章
- C++容器(五):set类型
- reactor模式与java nio
- 设计模式之Mediator模式(笔记)
- JAVA学习第二十七课(多线程(六))- 多生产者多消费者问题(JDK1.5新特性)
- Effective JavaScript Item 49 对于数组遍历,优先使用for循环,而不是for..in循环
- 小米净水器与小区过滤价格水对照.xls
- 2013亚洲区域赛长沙站 ZOJ 3732 Graph Reconstruction
- js实现图片上传后即时预览
- sql笔试题-1
- Linux下通过rdesktop连接Windows远程桌面