杭电多校第十场 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> ...
随机推荐
- 【iOS】The identity used sign the executable is no longer valid.
之前就遇到过这个问题,如图: 今天又遇到了,证书过期的问题. 需要访问苹果开发者的官网 http://developer.apple.com 来解决. 参考:How to fix “The ident ...
- eclipse使用(一)
使用eclipse时,编写对象的返回值非常麻烦,而使用返回值快捷键可以简化这一过程. 第一种 Alt+shift+L 将光标放在有返回值的代码句的分号后面: Resources.getResource ...
- 渐进式web应用开发---Service Worker 与页面通信(七)
_ 阅读目录 一:页面窗口向 service worker 通信 二:service worker 向所有打开的窗口页面通信 三:service worker 向特定的窗口通信 四:学习 Messag ...
- CSS等分布局方法
原文链接:http://caibaojian.com/css-equal-layout.html CSS等比例划分,在CSS布局中是比较重要的,下面分享几种常用方法和探讨一下兼容性. 一:浮动布局+百 ...
- [原创实践]IBM thinkpad T61制作和使用recovery光盘进行出厂系统恢复
制作系统恢复盘 之前制作了系统恢复光盘,包含Product recovery 光盘1和光盘2,rescure and recovery光盘. 联想笔记本XP系统有一个硬盘分区是用来做恢复的,双击硬盘即 ...
- c#自定义控件中的事件处理
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- 并发模型与IO模型梳理
并发模型 常见的并发模型一般包括3类,基于线程与锁的内存共享模型,actor模型和CSP模型,其中尤以线程与锁的共享内存模型最为常见.由于go语言的兴起,CSP模型也越来越受关注.基于锁的共享内存模型 ...
- 通过livy向CDH集群的spark提交任务
场景 产品中需要通过前端界面选择执行某种任务(spark任务),然后通过livy 的restful api 提交集群的spark任务 简单介绍下livy,翻译自官网: Livy是基于Apache许可的 ...
- Container killed by YARN for exceeding memory limits
19/08/12 14:15:35 ERROR cluster.YarnScheduler: Lost executor 5 on worker01.hadoop.mobile.cn: Contain ...
- 《Java 8 in Action》Chapter 1:为什么要关心Java 8
自1998年 JDK 1.0(Java 1.0) 发布以来,Java 已经受到了学生.项目经理和程序员等一大批活跃用户的欢迎.这一语言极富活力,不断被用在大大小小的项目里.从 Java 1.1(199 ...