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 ...
随机推荐
- zsh & tree & macOS
zsh & tree & macOS https://unix.stackexchange.com/questions/22803/counting-files-in-leaves-o ...
- 使用PHP对二维索引数组进行排序
本例中 data 数组中的每个单元表示一个表中的一行.这是典型的数据库记录的数据集合. 例子中的数据如下: volume | edition -------+-------- 67 | 2 86 | ...
- debug方法
debug as -> spring boot->开始了 可以添加 ,, 来进行向下步骤:使用其他方法(在方法内打点) 一步步F6就可以了
- Spring Boot 构建电商基础秒杀项目 (十二) 总结 (完结)
SpringBoot构建电商基础秒杀项目 学习笔记 系统架构 存在问题 如何发现容量问题 如何使得系统水平扩展 查询效率低下 活动开始前页面被疯狂刷新 库存行锁问题 下单操作步骤多,缓慢 浪涌流量如何 ...
- 3.docker基础架构
docker是一个典型的c/s架构产品. dockerd :为客户端提供 RESTFUL API,响应来自客户端的请求, 采用模块化的架构, 通过专门的 Engine 模块来分发管理各 个来自客户端 ...
- Ajax 调用的WCF
支持ajax 跨域调用的WCF搭建 1.新建一个"ASP.NET空Web应用程序"项目. 2.新建一个“WCF服务(支持ajax)”. 3.修改WCFAjaxService.svc ...
- redis哨兵集群+spring boot 2.×
Ubuntu集群构建篇 redis-cli:不跟参数,默认访问localhost:6379端口,无密码登陆 redis-cli -h ${host} -p ${port} -a ${password} ...
- 第五十五天 css基础入门
一.引入css的三种方式 1.行间式 <div style="width: 100px; height: 100px; background-color: red">& ...
- 洛谷P1395 会议 题解
$题目$ 为什么这个题会有图论的标签啊,虽然图论也包括找树的重心,可是这很容易让人联想到最短路,但不得不说,这是一个典型的找树的重心模板题. 树的重心是什么? 找到一个点,其所有的子树中最大的子树节点 ...
- git回滚部分文件到某个版本
reset 命令只能将整个版本的代码一起回滚,需要使用checkout 命令,可以还原部分文件到某一版本 格式为:git checkout [<branch>] [file] 1.首先使用 ...