Good Bye 2018 D. New Year and the Permutation Concatenation
https://www.cnblogs.com/violet-acmer/p/10201535.html
题意:
求 n 的所有全排列组成的序列中连续的 n 个数加和为 n*(n+1)/2 的区间个数。
题解:
n 最大为1e6,而n的全排列个数为 n! ,一共有 n*n!个数,存都存不下啊......
然后,第一反应就是,这题是找规律的。
一言不合就打表
==========
i=1
1
==========
i=2
2
==========
i=3
9
==========
i=4
56
==========
i=5
395
==========
i=6
3084
==========
i=7
26621
起初,想到了数 n 有 n! 个全排列,那么,这 n! 个全排列肯定满足条件,那么剩下的情况呢?
i=3 : 9=3!+3...........................3=3*1=3*(2-1);
i=4 : 56=4!+32.......................32=4*8=4*(9-1);
i=5 : 395=5!+275 ..................275=5*55=5*(56-1);
仔细观察一下括号中的2,9,56,相信这个规律很好找吧..........
AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll __int64
#define mem(a,b) memset(a,b,sizeof(a))
const ll MOD=;
const int maxn=1e6+; int n;
ll a[maxn]; int main()
{
cin>>n;
a[]=;
ll fact=;//阶乘
for(int i=;i <= n;++i)
{
fact=fact*i%MOD;
a[i]=fact+i*(a[i-]-);
a[i] %= MOD;
}
cout<<a[n]<<endl;
}
打表找规律代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e6; int p[maxn];
int b[maxn]; int main()
{
for(int i=;i <= ;++i)
{
for(int j=;j < i;++j)
b[j]=j+; int index=;
do
{
for(int j=;j < i;++j)
p[index++]=b[j];
}while(next_permutation(b,b+i));
int res=;
for(int j=;j+i <= index;++j)
{
int sum=;
for(int k=j;k < j+i;++k)
sum += p[k]; if(sum == i*(i+)/)
res++;
}
printf("==========\ni=%d\n",i);
printf("%d\n",res);
}
}
用到了一个骚操作:next_permutation();
爽歪歪,哈哈哈
Good Bye 2018 D. New Year and the Permutation Concatenation的更多相关文章
- Good Bye 2018
Good Bye 2018 2018年最后一场CF,OVER! 弱弱的我只能做出3道A,B,D~~~~ 最后几分钟,感觉找到了C题的规律,结束的那一刻,提交了一发 "Wrong answer ...
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- Good Bye 2018题解
Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...
- CF Good Bye 2018
前言:这次比赛爆炸,比赛时各种想多,导致写到\(D\)题时思路已经乱了,肝了\(1\)个多小时都没肝出来,\(B\)题中途因为没开\(long\ long\)又被\(HACK\)了..\(C\)题因为 ...
- Good Bye 2018 C. New Year and the Sphere Transmission
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: n 个people,编号1~n,按顺时针方向围城一圈: 初始,编号为1的peo ...
- Good Bye 2018 B. New Year and the Treasure Geolocation
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: 在二维空间中有 n 个 obelisk 点,n 个 p 点: 存在坐标T(x, ...
- Good Bye 2018 A. New Year and the Christmas Ornament
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题解: 这题没什么好说的,读懂题意就会了. 比赛代码: #include<ios ...
随机推荐
- bpmn.js & BPMN diagram
bpmn.js & BPMN diagram BPMN 2.0 for the web https://github.com/bpmn-io/bpmn-js https://demo.bpmn ...
- js外部调用layui.use中的函数的写法
layui模块化的写法固然不错,但也有让人不适应的一些地方 外部调用函数的写法就让人不太舒服 需要在函数名前面加上window这个前缀,就不太舒服 补充:window前缀,是全局变量的声明方式 如下: ...
- NPOI 上传Excel功能
1.首先写一个Excel表格,第一行数据库类型(varchar.date.decimal).第二行数据库类型长度(100.12,4.时间日期为空)2.html 加按钮 { type: "bu ...
- solrcloud编辑zookeeper上的配置文件的方法
solrcloud的配置文件是上传在zookeeper文件系统上的.这样就面临一个问题,每次需要修改配置文件,就没有只有之前本地单机solr那么简单,需要上传. 搭建solrcloud时候提交配置文件 ...
- codeforces231C
To Add or Not to Add CodeForces - 231C A piece of paper contains an array of n integers a1, a2, ..., ...
- poj-3080(kmp+暴力枚举)
题意:给你多个字符串,问你这几个字符串的最长公共子串是哪个,如果有多个,输出字典序最大的那个,如果最长的公共子串长度小于3,输出一个奇怪的东西: 解题思路:首先看数据,数据不大,开始简单快乐的暴力之路 ...
- sws_getContext函数参数介绍
原型: SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, ...
- windows动态库与Linux动态库
Linux动态库和windows动态库的目的是基本一致的,但由于操作系统的不同,他们在许多方面还是不尽相同.但是尽管有差异Linux动态库的windows动态库还是可以移植的,有一些规则以及经验是必须 ...
- html input 禁止输入中文
<input type="text" class="tel" onkeyup="value=value.replace(/[\u4e00-\u9 ...
- windows常用服务命令
windows运行打开服务命令的方法 :在开始->运行,输入以下命令 gpedit.msc-----组策略 sndrec32-------录音机 Nslookup-------IP地址侦测器 e ...