【UVa】Jump(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4198
约瑟夫变形
根据f(n)=(f(n-1)+m)%n
因为是求倒数第几个
那么我们只要求出f(倒数第几个)的值然后再带进去即可。
(没理解的自行面壁。。)
而f(倒数第几个)=(m-1)%倒数第几个
然后就行了。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } int getans(int t, int k, int n) {
int f=(k-1)%t;
for1(i, t+1, n) f=(f+k)%i;
int ret=(f+1)%n;
return ret==0?n:ret;
}
int main() {
int n, k, cs=getint();
while(cs--) {
read(n); read(k);
printf("%d %d %d\n", getans(3, k, n), getans(2, k, n), getans(1, k, n));
}
return 0;
}
【UVa】Jump(dp)的更多相关文章
- 【UVa】Salesmen(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 【2039】checker(Dp)
我今天脑子貌似又好使了一点,可以做一做DP中的水题了. 这个题难度蓝色,纯属是做的人太少了虚高. 这个题很显然的是可以用一个顺序一个逆序这两个大水转移方程轻松转移出到达这个地方最少需要的棋子数量,然后 ...
- 【HDOJ6578】Blank(DP)
题意:一个长为n的序列,每个位置上的值是0,1,2,3中的一个,有m个限制条件,限制位置[l[i],r[i]]中不同的数值有x[i]个,问方案数MOD 998244353 n<=100,m< ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 【BZOJ1996】合唱队(动态规划)
[BZOJ1996]合唱队(动态规划) 题面 BZOJ 题解 很容易的一道题 因为每个人不是放在了左边就是放在了右边 所以每次放好的人必定是原序列的一个子串 所以,很容易想到区间\(dp\) 设\(f ...
- 【BZOJ1899】午餐(动态规划)
[BZOJ1899]午餐(动态规划) 题面 BZOJ 题解 我太弱了 这种\(dp\)完全做不动.. 首先,感性理解一些 如果所有人都要早点走, 那么,吃饭时间长的就先吃 吃饭时间短的就晚点吃 所以, ...
- 【BZOJ1040】骑士(动态规划)
[BZOJ1040]骑士(动态规划) 题面 BZOJ 题解 对于每一组厌恶的关系 显然是连边操作 如果是一棵树的话 很显然的树型\(dp\) 但是,现在相当于有很多个基环 也就是在一棵树的基础上再加了 ...
- 【BZOJ5416】【NOI2018】冒泡排序(动态规划)
[BZOJ5416][NOI2018]冒泡排序(动态规划) 题面 BZOJ 洛谷 UOJ 题解 考场推出了就是两个上升子序列,并且最长下降子序列长度不超过\(2\)...然后大力暴力状压\(dp\)混 ...
- 【BZOJ1068】压缩(动态规划)
[BZOJ1068]压缩(动态规划) 题面 BZOJ 洛谷 题解 比较简单的\(dp\) 设\(f[i][j]\)表示当前已经匹配到了原串的第\(i\)个位置,上一个\(M\)在第\(j\)个字符之后 ...
随机推荐
- 查看物体A是否被相机B渲染
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { public GameObject a ...
- Linux 监测内存常用的工具sar free vmstat
Linux 检测内存常用的工具sar free vmstat free 内存统计信息解释 total 内存总量used 内存使用的大小free 内存剩余大小shared 共享内存大小buffers 块 ...
- SlidingMenu(一)
我们一般称之为侧边栏,今天下倒腾了一下,留点笔记... 源码来自:https://github.com/jfeinstein10/SlidingMenu 来张图把: 代码API注释看看这个吧 http ...
- Java Callable 与 Future
- Flume入门:安装、部署
一.什么是Flume? flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original genera ...
- 破解Aspose 操作pdf word等文档 对10以下版本有效
using System; using System.IO; namespace LicenseHelper { public static class License { public const ...
- pandas如何去掉时间列的小时只保留日期
最近无聊,想玩玩数据挖掘,就拿天池的天池新人实战赛之[离线赛]练练手.https://tianchi.aliyun.com/getStart/information.htm?spm=5176.1000 ...
- Python -- 函数对象
转自:http://www.cnblogs.com/vamei/archive/2012/07/10/2582772.html 秉承着一切皆对象的理念,我们再次回头来看函数(function).函数也 ...
- python笔记-print输出
print语句默认是输出一行后添加一个换行符 >>> for item in ['apple','ibm','google','oracle']: ... print item .. ...
- android何如获取SIM卡提供国家代码(ISO)
TelephonyManager telManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); telMana ...