杭电多校第十场 hdu6432 Cyclic 打表找规律
Cyclic
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 193 Accepted Submission(s): 125
Output the answer modulo 998244353.
In each test case, there is a single integer n in one line, denoting the length of cyclic permutations.
1 ≤ T ≤ 20, 1 ≤ n ≤ 100000
4
5
6
8
36
题意:求满足一个方向的(a[i]+1)%n!=a[i+1]循环数列的n个数字组成的数列的可能性
分析:首先按照题目的意思做一个全排列列出前面几项的可能数
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll a[maxn];
int main() {
ios::sync_with_stdio(0);
ll T, n;
scanf("%lld",&T);
while( T -- ) {
scanf("%lld",&n);
for( ll i = 0; i < n; i ++ ) {
a[i] = i+1;
}
ll cnt = 0;
while(next_permutation(a,a+n)) {
bool flag = true;
for( ll i = 0; i < n-1; i ++ ) {
ll t;
if( (a[i]+1)%n == 0 ) {
t = a[i]+1;
} else {
t = (a[i]+1)%n;
}
if( t == a[i+1] ) {
flag = false;
break;
}
}
ll t;
if( (a[n-1]+1)%n == 0 ) {
t = a[n-1]+1;
} else {
t = (a[n-1]+1)%n;
}
if( t == a[0] ) {
flag = false;
}
if(flag) {
cnt ++;
/*for( ll i = 0; i < n; i ++ ) {
cout << a[i] << " ";
}
cout << endl;*/
}
}
printf("%lld\n",cnt/n);
}
return 0;
}
接着找规律
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll a[maxn];
int main() {
ios::sync_with_stdio(0);
ll T, n;
a[1] = 0, a[2] = 0, a[3] = 0, a[4] = 1, a[5] = 8, a[6] = 36;
for( ll i = 7; i <= maxn-10; i ++ ) {
a[i] = ((i-3)*a[i-1]%mod+(i-2)*(2*a[i-2]+a[i-3])%mod)%mod;
}
scanf("%lld",&T);
while( T -- ) {
scanf("%lld",&n);
printf("%lld\n",a[n]);
}
return 0;
}
杭电多校第十场 hdu6432 Cyclic 打表找规律的更多相关文章
- 杭电多校第十场 hdu6435 CSGO 二进制枚举子集
CSGO Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Subm ...
- 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板
Problem I. Count Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- Make Rounddog Happy(2019年杭电多校第十场1011+HDU6701+启发式分治)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 求有多少个子区间满足\(a_l,a_{l+1},\dots,a_r\)均不相同且\(max(a_l,a_{l+1},\dots,a_r)-(r ...
- [2019杭电多校第十场][hdu6701]Make Rounddog Happy
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6701 题目大意为求满足 $max(a_{l},a_{l+1}\cdot \cdot \cdot a_{ ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- 2018杭电多校第三场1003(状态压缩DP)
#include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...
- HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场
题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...
- HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...
- HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场
题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...
随机推荐
- 【Android Studio】Frameworks detected: Android framework is detected in the project Configure
刚开始在 Mac 上用 Android Studio, 打开第一个项目就遇到了问题,描述如下: 上午9:: Frameworks detected: Android framework is dete ...
- Pyinstaller 打包工具的使用!!!
打包成一个文件夹: pyinstaller xxx.py 打包成单个文件: pyinstaller -F xxx.py 打包成不显示终端的单个文件: pyinstaller -F -w xxx.py ...
- js常用事件列表
onmousedown.onmouseup 以及 onclick 事件 onmousedown, onmouseup 以及 onclick 构成了鼠标点击事件的所有部分.首先当点击鼠标按钮时,会触发 ...
- vue-cli3.0创建项目报npm install --loglevel error 踩坑的那把辛酸泪
创建项目 vue create vue-pro 然后如下图 一开始以为是npm的问题,卸载了Mac的node ,安装nvm,然后再安装node (可参考: Mac中nvm的安装和使用 https: ...
- 控制台出现_ob_:Obsever
我遇到一个问题:我的代码想让他点击之后得到经纬度坐标数组,然后我就这样写了 然而控制台却读取出了
- React 如何搭建脚手架
React 如何搭建脚手架 npm install -g create-react-app //安装 create-react-app react-demo // react-demo ...
- MQ服务器端和客户端通信浅谈
MQ服务器端和客户端通信浅谈 1. WebSphere MQ的服务端的安装和配置 (1)创建名为venus.queue.manager的默认队列管理器. 在DOS窗口命令提示符下,输入以下命令: cr ...
- JavaWeb——使用会话维持状态
1.会话的作用 使用会话是为了维持状态,维持的是请求域请求之间的状态.因为HTTP请求自身是完全无状态的.从服务器的角度来看,当用户发出第一个请求开始,服务器无法将新的请求与之前的请求关联起来,举例说 ...
- python 函数和函数名的应用
一.函数 1.函数定义 def 关键字 -- 定义 func 函数名 -- 和变量定义规则一样 ()必须要写格式 : 声明语句结束 def my_len(): 函数体 def func(a:int ...
- Linux之各程序安装
python安装 安装python3.6 安装python前的库环境,非常重要 yum install gcc patch libffi-devel python-devel zlib-devel b ...