传送门

https://www.cnblogs.com/violet-acmer/p/10201535.html

题意

  $n$ 个 $people$,编号 $1,2,3,\cdots ,n$ ,按顺时针方向围城一圈;

  初始,编号为 $1$ 的 $people$ 抱着一个球,他可以将球顺时针传给他左手边的第 $k$ 个 $people$;

  接到球的 $people$ 依次将球传给他顺时针方向的第 $k$ 个 $people$;

  循环进行,直到球再一次落到 $1$ 号 $people$ 手中,结束;

  定义一个开心值 :所有接到球的 $people$ 的编号和。

  求所有的开心值,并按升序排列。

题解

  弱弱的我只能通过打表找规律%%%%%%%那些一眼看出规律的大神们 

  $\begin{aligned} k &= 1\rightarrow 1 \\ k&= 2\rightarrow 1,3 \\ k&= 3\rightarrow 1,6 \\ k&= 4\rightarrow 1,4,10 \\ k&= 5\rightarrow 1,15 \\ k&= 6\rightarrow 1,5,9,21 \\ k&= 7\rightarrow 1,28\end{aligned}$

  刚开始,发现,有些数的开心值只有两个,然后,把这些只有两个开心值的数列了一下,发现,全是素数。

  不知为啥,求了一下每个数的因子个数,发现没,开心值的个数与他们的因子个数有关!!!

  然后,在草纸上列出了前 12 项的答案,找了一下规律,哇,最后10分钟,找到了一个前10个通用的规律。

  最后结束时刻提交,emmmmm,wa

  然后,睡觉,哈哈哈。

  今天,把昨天的错误数据看了一下,重新找了一下规律

  emmmm,找到了

  以 $k=15$ 为例:

    $15$ 的因子为 $1,3,5,15$

    开心值为 $1,18,35,120$

    1=1;

    18=1+6+11;                    //d=5,tot=3

    35=1+4+7+10+13;                   //d=3,tot=5

    120=1+2+3+4+5+6+7+8+9+10+11+12+13+14+15;         //d=1,tot=15

  发现没,开心值就是以 $15$ 的因子为公差的前 $tot$ 项和;

•Code

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll __int64
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e6+; ll n;
ll a[maxn];
ll res[maxn]; int factor()//求出n的所有因子
{
int x=sqrt(n);
a[]=;
int index=;
for(int i=;i <= x;++i)
{
if(n%i == )
{
a[++index]=i;
if(n/i != i)
a[++index]=n/i;
}
}
a[++index]=n;
return index;
}
int main()
{
scanf("%d",&n);
int t=factor();
sort(a+,a+t+);
for(int i=;i <= t;++i)
{
ll d=a[i],tot=n/d;
ll a1=,an=a1+(tot-)*d;
res[i]=tot*(a1+an)/;
}
for(int i=t;i >= ;--i)
printf("%I64d ",res[i]);
}

•打表找规律代码

 #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;
int a[maxn]; int main()
{
for(int i=;i <= ;++i)
{
i=;
int tot=;
for(int k=;k <= i;++k)
{
int res=;
int index=+k;
printf("****\nk=%d\n",k);
printf("");
while(index != )
{
if(index > i)
index %= i;
if(index == )
break;
res += index;
printf("+%d",index);
index += k;
}
printf("=%d\n",res);
a[tot++]=res;
} sort(a,a+tot);
int t=unique(a,a+tot)-a;
printf("\n===========\ni=%d\n",i);
for(int j=;j < t;++j)
printf("%d ",a[j]);
break;
}
}
//1 27 105 235 625 1275

分割线2019.6.14

感悟

  因打表找规律而AC的题,不能当作正解,赛后补题,要花时间思考正解;

•想法

  从编号为 $1$ 的 $people$ 开始传球,依次传给其顺时针方向的第 $k$ 个人;

  可以肯定的是,球一定会回到 $1$ 手中,假设传了 $x$ 次,球重新回到 $1$ 手中;

  并假设这 $x$ 次传球,共传了 $y$ 轮,如下图所示:

  

第 i 轮对应的序列 $(i-1)\cdot n+1,(i-1)\cdot n+2,\cdots ,i\cdot n$ 对应的 $people$ 编号为 $1,2,\cdots ,n$;

  也就是 $1+x\cdot k = 1+y\cdot n$,即 $x\cdot k = y\cdot n$;

  我们来分析一下这个等式可以推出什么神奇的东西:

  

  为什么要最小的 $x$ 呢?

  因为只要传球期间来到 $1$ 就停止,所以需要的是最小的 $x$;

  如果 $GCD(k,n) = k$,那么传一轮便可以来到 $1$ 处;

  如果 $GCD(k,n) \neq k$,那么需要传多轮才能来到 $1$ 处;

  那么下面来讨论 $GCD(k,n) \neq k$  的情况;

  假设 $GCD(k,n) = f$,这种情况下共传球 $x=\frac{n}{f}$ 次,与 $k=f$ 的传球次数相同;

  又因为 $f\ |\ k$,所以,这 $x$ 次传球的 $people$ 的编号一定相同;

  所以,对于任意 $k$,传球次数和编号只与 $GCD(n,k)$ 有关系;

  也就是只和 $n$ 的因子有关系;

  当 $GCD(n,k) = f$ 时,接到球的 $people$ 编号为:

    $1\rightarrow (1+f)\rightarrow (1+2f) \rightarrow \cdots \rightarrow (1+xf)$;

  共传球 $x=\frac{n}{f}$ 次;

  满足首项 $a_1=1$,末项 $a_{x+1}=n+1$,公差 $d=f$ 的等差数列;

  前 $x$ 项和即为当前的开心值;

•Code

 #include<bits/stdc++.h>
using namespace std;
#define ll long long int n;
vector<int >f;
vector<ll >ans; void Factor(int n)///求解 n 的因子
{
f.clear();
for(int i=;i*i <= n;++i)
{
if(n%i != )
continue; f.push_back(i);
if(n/i != i)
f.push_back(n/i);
}
}
void Solve()
{
Factor(n); for(int i=;i < f.size();++i)
{
ll d=f[i];
ll x=n/f[i];
ll s=x*(++(x-)*d)/;
ans.push_back(s);
}
sort(ans.begin(),ans.end());
for(int i=;i < ans.size();++i)
printf("%lld ",ans[i]);
}
int main()
{
scanf("%d",&n);
Solve(); return ;
}

应用

•题目描述

•题解

  使得所有人都拿过球,类比于上题,也就是说求使得开心值为 $1+2+3+\cdots +n$ 的最大的 $k$;

  那么,只有当 $GCD(n,k)=1$ 时,球才会传递给 $x=n$ 个人;

  那么,本题就转化为求解 $GCD(n,k) = 1$ 的,并且满足 $k \le n$ 的最大的 $k$;

  显然,$k=n-1$ 为满足条件的最大的 $k$;

•变形

  如果限制 $k \le \frac{n}{2}$ 呢?

•分析

  如果 $n$ 为奇数,那么 $\lfloor{ \frac{n}{2} }\rfloor$ 一定与 $n$ 互素;

  如果 $n$ 为偶数,那么,如果 $\frac{n}{2}$ 为奇数,答案为 $\frac{n}{2}-2$;

  反之,如果 $\frac{n}{2}$ 为偶数,那么答案为 $\frac{n}{2}-1$,因为奇数与偶数一定互素;

  也就是说,直接判断 $\lfloor{ \frac{n}{2} }\rfloor\ ,\ \lfloor{ \frac{n}{2} }\rfloor-1\ ,\ \lfloor{ \frac{n}{2} }\rfloor-2$ 这三个数哪个与 $n$ 互素即可;

Good Bye 2018 C. New Year and the Sphere Transmission的更多相关文章

  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 D. New Year and the Permutation Concatenation

    传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: 求 n 的所有全排列组成的序列中连续的 n 个数加和为 n*(n+1)/2 的 ...

  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. 集合之LinkedList(含JDK1.8源码分析)

    一.前言 LinkedList是基于链表实现的,所以先讲解一下什么是链表.链表原先是C/C++的概念,是一种线性的存储结构,意思是将要存储的数据存在一个存储单元里面,这个存储单元里面除了存放有待存储的 ...

  2. python 第三方包安装

    1.tqdm 安装  pip install tqdm 使用时可能会报缺少stopwords.punkt错,原因是缺失相应文件,下载即可: import nltk nltk.download('sto ...

  3. Linux压缩和解压命令

    zip命令: 压缩 :zip -r files.zip fileFolder 解压:unzip files.zip tar命令: 压缩:tar -cvf files.tar fileFolder 解压 ...

  4. 51-node-1649齐头并进(最短路)

    题意:中文题,没啥坑点: 解题思路:这道题一开始以为要跑两个最短路,后来发现不用,因为如果给定了铁路的线路,那么,公路一定是n个节点无向图的补图,所以,铁路和公路之间一定有一个是可以直接从1到n的,我 ...

  5. linux常用命令(个人总结)

    1.快捷键: ctrl + l           --------------------清屏 ctrl + c          --------------------退出当前命令 ctrl + ...

  6. HDU3966-Aragorn's Story-树链剖分-点权

    很模板的树链剖分题 注意什么时候用线段树上的标号,什么时候用点的标号. #pragma comment(linker, "/STACK:102400000,102400000") ...

  7. 2018-01微信小程序--直播

    一. 小程序直播支持的格式 目前小程序支付两种格式直播 1) flv格式直播 2) rtmp格式直播 二. 能够开通小程序直播的行业类目 由于直播需要资质, 并不是每个企业都能够开通小程序直播, 微信 ...

  8. requirements文件

    将一个环境中安装的所有的包在另一个环境中安装 1.生成文件列表 pip freeze > requirements.txt 2.将该文件放入到新环境中,安装 pip install -r req ...

  9. JDK9.0.4环境变量配置

    电脑不知道怎么就崩溃了...重置了一下,啥都没了 所有都得重新配置 wnm系列之jdk安装与配置 jdk下载,选择windows版本 http://www.oracle.com/technetwork ...

  10. 「HNOI2016」最小公倍数

    链接 loj 一道阔爱的分块 题意 边权是二元组(A, B),每次询问u, v, a, b,求u到v是否存在一条简单路径,使得各边权上\(A_{max} = a, B_{max} = b\) 分析 对 ...