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 ...
随机推荐
- Python:matplotlib绘制直方图
使用hist方法来绘制直方图: 绘制直方图,最主要的是一个数据集data和需要划分的区间数量bins,另外你也可以设置一些颜色.类型参数: plt.hist(np.random.randn(1 ...
- 使用ultraiso制作启动盘安装windows操作系统
1. 使用ultraiso制作u盘启动盘 在电脑上安装ultraiso: 启动ultraiso,文件->打开->选中iso镜像文件 菜单栏->启动->写入硬盘映像 a. 便捷启 ...
- Lodop输出页面input文本框的最新值
默认使用Lodop打印页面上的文本框等,会发现虽然页面上文本框输入了值,打印预览却是空的,这是由于没有把最新的值传入Lodop. 如图,演示的是Lodop如何输出文本框内的新值,这里整个页面只有inp ...
- .NET提供了三种后台输出js的方式:
.NET提供了三种后台输出js的方式: 首先创建 js文件testjs.js { Page.ClientScript.RegisterClientScriptInclude("keys ...
- hdu-1686(kmp)
题意:前面的都是废话...其实直接看输入要求和输出要求就可以了,就是给你两个字符串,问你第一个字符串在第二个字符串中出现几次: 解题思路:kmp... 代码: #include<iostream ...
- hdu-1058(map)
题意:输出第n个能拆分成由,2,3,5,7中的一个或者多个组成的数: 解题思路:a[i+1]=a[i]*2;a[i+2]=a[i]*3;a[i+3]=a[i]*5;a[i+4]=a[i]*7;然后把重 ...
- 解决Maven依赖报错问题
问题现象:从svn上签下源代码,本地执行打包命令,提示如下错误: [ERROR] Failed to execute goal on project dddwriter: Could not reso ...
- Codeforces Round #445 Div. 1
A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...
- CodeCraft-19 and Codeforces Round #537 Div. 2
D:即有不超过52种物品,求容量为n/2的有序01背包方案数.容易想到设f[i][j]为前i种物品已用容量为j的方案数,有f[i][j]=f[i-1][j-a[i]]*C(n/2-j+a[i],a[i ...
- B - I Hate It HDU - 1754 线段树区间最大值板子(单点更新,区间最大)
第一次打 改了半天 各种小错误 难受 #include<cstdio> #include<iostream> using namespace std; +; int a[ma ...