UVALive
来源:互联网 发布:seo公司排行榜 编辑:程序博客网 时间:2024/06/11 02:57
约瑟夫环问题:求最后三个出去的人
#include <stdio.h>#include <algorithm>#include <iostream>#include <string.h>using namespace std;typedef long long ll;int f[555555],a[11];int main(){int t;cin>>t;int m,n;while(t--){cin>>n>>m;//求最后一个人的位置时f[1]=(m-1)%1;//求倒数第二个人的位置时f[2]=(m-1)%2;//求倒数第三个人的位置时f[3]=(m-1)%3;for(int i=1;i<=3;i++){f[i]=(m-1)%i;for(int j=i+1;j<=n;j++){f[j]=(f[j-1]+m)%j;}a[i-1]=(f[n]+1);}printf("%d %d %d\n",a[2],a[1],a[0]);}return 0;}
阅读全文
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- FTI Sculptured Die Face(钣金冲压设计)v3.2官方版下载
- L LAMP环境搭建与配置(二)
- 模拟实现strcpy,strcmp,等str~系列函数
- 【OpenGL】斯坦福兔子、显示列表
- 计算从1990.01.01到某一天的天数
- UVALive
- yum 使用记录
- 在 spring boot 中使用spring cache + redis
- Android中HashMap内存优化之ArrayMap和SparseArray
- 37.开源项目--git+repo+gerrit环境介绍
- Android性能优化之提高ListView性能的技巧
- 判断一个数是不是2的整数次幂(两种方法)
- Struts2学习笔记(6)-异常处理
- 文件类型与权限