传送门

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. 安装使用阿里云的yum源

    CentOS 1.备份(备份本地Yum源) mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 2.下 ...

  2. 集合之TreeMap(含JDK1.8源码分析)

    一.前言 前面所说的hashMap和linkedHashMap都不具备统计的功能,或者说它们的统计性能的时间复杂度都不是很好,要想对两者进行统计,需要遍历所有的entry,时间复杂度比较高,此时,我们 ...

  3. Shell 编程和Python编程的那些不同之处(一)

    循环 shell中for循环的表现形式: 1.数字段形式 for i in {1..10};do  echo $i;done 还支持按规定的步数进行跳跃的方式实现列表for循环,例如计算1-100内所 ...

  4. dreamweavercs 和dreamweaver cc的區別

    https://zhidao.baidu.com/question/1541178469432885667.html

  5. Oracle 查询两个时间段内的所有日期列表

    1.查询某时间段内日期列表 select level,to_char(to_date('2013-12-31','yyyy-mm-dd')+level-1,'yyyy-mm-dd') as date_ ...

  6. SQL 给视图赋权限

    授予表权限 创建视图 授予视图权限 测试权限 复杂程度: 初级 数据要求: 使用自备的数据 您可以使用 SQL 在企业级地理数据库中创建表和要素类的视图. 本主题中的示例显示如何使用 Microsof ...

  7. linux 目录分类与文件操作

    / 虚拟根目录 一般不会在这里存储文件 /bin 二进制目录,存放需要GNU用户级的工具 /boot 启动目录,存放启动文件 /dev 设备目录,linux在这里创建设备节点 /etc 系统配置文件目 ...

  8. 最简单的socket服务器与客户端

    服务器: //服务器 #include <stdio.h> #include <netinet/in.h> #include <unistd.h> #include ...

  9. 【BZOJ1007】【HNOI2008】水平可见直线 几何 单调栈

    题目大意 给你\(n\)条直线\(y=kx+b\),问你从\(y\)值为正无穷大处往下看能看到那些直线. \(1\leq n\leq 500000\) 题解 如果对于两条直线\(l_i,l_j\),\ ...

  10. require.js基本用法

    1.require.js的加载 使用require.js的第一步,是先去官方网站下载最新版本. 下载后,假定把它放在js子目录下面,就可以加载了. 1 <script src="js/ ...