HDU 5668 Circle
来源:互联网 发布:windows 杀进程 编辑:程序博客网 时间:2024/06/01 23:10
Problem Description
Input
Output
Sample Input
177 6 5 4 3 2 1
Sample Output
420约瑟夫环问题,可以转换成中国剩余定理,然后就是套模板了。
#pragma comment(linker, "/STACK:102400000,102400000")#include<map>#include<set>#include<cmath>#include<queue>#include<stack>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>using namespace std;typedef long long LL;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int maxn = 1e5 + 10;int T, n, x[maxn], y;LL a[maxn], b[maxn], vis[maxn];void egcd(LL a, LL b, LL&d, LL&x, LL&y){if (!b) { d = a, x = 1, y = 0; }else{egcd(b, a%b, d, y, x);y -= x*(a / b);}}LL lmes() {LL M = a[1], R = b[1], x, y, d;for (int i = 2; i <= n; i++) {egcd(M, a[i], d, x, y);if ((b[i] - R) % d) return -1;x = (b[i] - R) / d*x % (a[i] / d);R += x*M;M = M / d*a[i];R %= M;}return (R + M) % M ? (R + M) % M : M;}int main(){scanf("%d", &T);while (T--){scanf("%d", &n);for (int i = 1; i <= n; i++){a[i] = n - i + 1;vis[i] = 0;scanf("%d", &y);x[y] = i;}for (int i = 1, j = 1, k; i <= n; i++){for (k = 1; j != x[i];) { if (!vis[j]) k++; j = j % n + 1; }vis[x[i]] = 1; b[i] = k % a[i];}LL k = lmes();if (k == -1) printf("Creation August is a SB!\n");else cout << k << endl;}return 0;}
0 1
- HDU 5668 Circle
- HDU 5668:Circle 同余方程
- HDU-Rectangle and Circle
- Different Circle Permutation HDU
- HDU 5668 Circle (约瑟夫游戏,求解同余方程组)
- hdu-5668- Circle 逆元+卡特兰数知识模板
- HDU 5868 Different Circle Permutation
- circle ``
- Circle
- circle
- HDU-5668-Circle(中国余数定理/解同余方程组)
- HDU 3964 Find The Simple Circle
- Hdu 4566 Circle Game 2013长沙邀请赛
- hdu 1374 The Circumference of the Circle
- HDU1221---Rectangle and Circle HDU(94)
- hdu 4669 Mutiples on a circle
- 【数学】hdu 1221 Rectangle and Circle
- HDU - 4669 Mutiples on a circle
- 冒泡、选择、插入排序
- 入门Android开发--第一行代码--笔记系列(问)
- VC PreTranslateMessage详解
- The import android.support.v7.app cannot be resolved
- wait/notify实现生产消费模型
- HDU 5668 Circle
- linux下ssh的一些基本配置
- 愿你目标清晰,从不曾动摇。。。
- 哎
- 10w分区表,hive能跑,sparksql运行也完全能跑起来
- Near Field Communication(nfc近场通信)——翻译自developer.android.com
- 第六章、android的Drawable
- 单链表的插入操作的实现(0952)
- asp.net Forms身份验证详解