【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
【题目链接】:http://codeforces.com/contest/822/problem/D
【题意】
有n个人参加选美比赛;
要求把这n个人分成若干个相同大小的组;
每个组内的人数是相同的;
然后每个组内的人,两两比较;
每个组得出最美的人;
然后每个组中最美的人再重复上述步骤;
直到只剩一个人;
问你如何选定每个阶段的分组;
使得比较的次数最少;
【题解】
只考虑一轮的情况;
设x是分组后每个组的人数;
然后一共有n个人;
则这一轮比较的次数就为
nx∗x∗(x−1)2
->n∗(x−1)2
这样看来x最小的时候效果最好;
则每个数字都取最小的因子就好;
这样设数字i的最小因子为p[i]
则设dp[i]表示i个人的时候最少需要多少次比较
dp[n]=dp[np[i]]+p[i]∗p[i−1]2∗np[i]
用筛法求出每个数的最小因子就好;
(最小因子都是质数吧.)
【Number Of WA】
0
【反思】
这种题做得比较少吧;
每一轮是独立的!
递推+贪心的方法;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int INF = 5e6+10;
const LL MOD = 1e9+7;
LL t,l,r;
LL p[INF],f[INF];
int main(){
//Open();
Close();
cin >> t >> l >> r;
rep1(i,1,(int) 5e6)
p[i] = i;
rep1(i,2,sqrt((int) 5e6)){
if (p[i]==i){
for (int k = i;k <= (int) 5e6;k+=i)
if (p[k]==k)
p[k] = i;
}
}
rep1(i,1,(int) 5e6 ){
f[i] = ((p[i]*(p[i]-1)/2)%MOD*(i/p[i])%MOD + f[i/p[i]])%MOD;
}
LL now = 1;
LL ans = 0;
rep1(i,(int)l,(int)r){
ans = (ans + now*f[i])%MOD;
now = (now*t)%MOD;
}
cout << ans << endl;
return 0;
}
【Codeforces Round #422 (Div. 2) D】My pretty girl Noora的更多相关文章
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- 【Codeforces Round #422 (Div. 2) B】Crossword solving
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...
- 【Codeforces Round #422 (Div. 2) A】I'm bored with life
[题目链接]:http://codeforces.com/contest/822/problem/A [题意] 让你求a!和b!的gcd min(a,b)<=12 [题解] 哪个小就输出那个数的 ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)
接上一篇文章; 这里直接把左端点和右端点映射到vector数组上; 映射一个open和close数组; 枚举1..2e5 如果open[i]内有安排; 则用那个安排和dp数组来更新答案; 更新答案完之 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- android全屏去掉title栏的多种实现方法
android全屏去掉title栏的多种实现方法 作者: 字体:[增加 减小] 类型:转载 时间:2013-02-18我要评论 android全屏去掉title栏包括以下几个部分:实现应用中的所有ac ...
- [codevs3955]最长严格上升子序列(加强版)
题目大意:给你一个序列,要你求该序列中最长严格上升子序列的长度. 解题思路:此题算是一道LIS模板题.普通的$O(n^2)$的LIS是会TLE的,因为$n\le 1000000$,所以此题要用单调队列 ...
- 将页面的内容导出使用html2canvas+jsPDF
第一首先是要引用 import jsPDF from 'jspdf' import html2canvas from 'html2canvas' import PDFJS from 'pdfjs-di ...
- POJ 3155 Hard Life
Hard Life Time Limit: 8000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: ...
- cocos2dx 几个精灵依照顺序播放动画解决方法
我先描写叙述一下这个问题: 拿之前做的卡牌游戏来说.假设一方场上有3张牌,那么肯定要以一种顺序来播放攻击动画.我是以从左到右的方式. 我的解决方案是向每张牌都传递一个延时參数,然后在runAction ...
- HDU 2112 HDU Today <SPFA算法+map函数>
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- programming-challenges Shoemaker's Problem (110405) 题解
Greedy. 证明: Let's say we have job 1, 2, ..., n, and they have time and fine as t1, f1, t2, f2, ..., ...
- ASP.NET Application and Page Life Cycle
ASP.NET Application Life Cycle Overview for IIS 7.0 https://msdn.microsoft.com/en-us/library/bb47025 ...
- 关于安装Ubuntu系统时提示“分配到/的分区/dev/sdax开始于xxxx字节,使用磁盘的最小对齐,这可能造成非常差的性能..."的解决办法
由于Windows系统的VMware出了一些问题,索性就不用VM了,直接装上双系统好了.但是在最后安装时出现错误提示“分配到/的分区/dev/sdc1开始于3584字节,使用磁盘的最小对齐,这可能造成 ...
- Intellij使用"easyexplore"
刚开始接触Intellij,里面有很多东西还不太会用,平时在eclipse里面用的很方便的easyexplore能帮助快速打开文件目录,Intellij中本身就有这样的功能,只是默认没有开启,需要我们 ...