传送门

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的更多相关文章

  1. Good Bye 2018

    Good Bye 2018 2018年最后一场CF,OVER! 弱弱的我只能做出3道A,B,D~~~~ 最后几分钟,感觉找到了C题的规律,结束的那一刻,提交了一发 "Wrong answer ...

  2. Good Bye 2018 (A~F, H)

    目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...

  3. Codeforces Good Bye 2018

    咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...

  4. Codeforces:Good Bye 2018(题解)

    Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...

  5. Good Bye 2018题解

    Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...

  6. CF Good Bye 2018

    前言:这次比赛爆炸,比赛时各种想多,导致写到\(D\)题时思路已经乱了,肝了\(1\)个多小时都没肝出来,\(B\)题中途因为没开\(long\ long\)又被\(HACK\)了..\(C\)题因为 ...

  7. 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 ...

  8. 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, ...

  9. Good Bye 2018 A. New Year and the Christmas Ornament

    传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题解: 这题没什么好说的,读懂题意就会了. 比赛代码: #include<ios ...

随机推荐

  1. MySQL系列:视图基本操作(3)

    1. 视图简介 1.1 视图定义 视图是一种虚拟的表,是从数据库中一个或多个表中导出来的表. 视图可以从已存在的视图的基础上定义. 数据库中只存放视图的定义,并没有存放视图中的数据,数据存放在原来的表 ...

  2. fiddler学习笔记2 字段说明;移动设备、解密证书

    # :           抓取顺序从1开始递增 result:    http 请求状态 protocol:   请求使用的协议如:http https ftp Host:         请求地址 ...

  3. Mybatis之collection嵌套查询mapper文件写法

    mapper.xml写法举例 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper ...

  4. Java使用RabbitMQ之整合Spring(生产者)

    依赖包 <!--RabbitMQ集成spring--> <!-- https://mvnrepository.com/artifact/org.springframework.amq ...

  5. ES 6 系列 - Promise

    一.含义 是异步编程的一种解决方案,es 6 将其变成了标准. 简单的说是一个容器,里面保存了某个未来才会结束的事件(通常是一个异步操作)的结果.语法上, Promise 是一个对象,从它可以获取异步 ...

  6. How to mount EFI on macOS

    mount -t msdos /dev/disk0s1 /volumes/efi

  7. hdu1875(最小生成树prime)

    思路:一开始想用贪心来着,发现贪心有缺陷,然后就用了最小生成树来写,这里用了prime算法,首先,先建个图,两点之间的边的权值就是两个点的距离,然后直接prime模板 代码 #include<i ...

  8. [Codeforces235D]Graph Game——概率与期望+基环树+容斥

    题目链接: Codeforces235D 题目大意:给出一棵基环树,并给出如下点分治过程,求点数总遍历次数的期望. 点分治过程: 1.遍历当前联通块内所有点 2.随机选择联通块内一个点删除掉 3.对新 ...

  9. BZOJ1565[NOI2009]植物大战僵尸——最大权闭合子图+拓扑排序

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  10. A - 敌兵布阵 HDU - 1166 线段树(多点修改当单点修改)

    线段树板子题练手用 #include<cstdio> using namespace std; ; int a[maxn],n; struct Node{ int l,r; long lo ...