Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E
dp
好题
*(if 满足条件)
满足条件 *1
不满足条件 *0
///这代码虽然写着方便,但是常数有点大
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e6+; /*
dp题
检查:
1.认真检查公式
2.认真检查代码
3.造一个规模适中的数据
手动推导
对应程序的结果
判断是否相同
*/ ///+1 20->21 2->3
///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
///1e18*k k<=9
int f[maxn][21][3],v[21][3]; int main()
{
int n,two,three,i,j,k;
scanf("%d",&n);
two=log(n+eps)/log();///+eps
three=(1.0*n/(<<two)>=1.5);
for (i=;i<=two;i++)
for (j=;j<=three;j++)
v[i][j]=n/((<<i)*(j==?:)); f[][two][]=;
if (three==)
f[][two-][]=;
for (i=;i<=n;i++)
for (j=;j<=two;j++)
for (k=;k<=three;k++)
///乘1ll,最后强制转换long long 转 int
f[i][j][k]=( 1ll*f[i-][j][k]*(v[j][k]-(i-))*((v[j][k]-(i-))>=)%mod + 1ll*f[i-][j+][k]*(v[j][k]-v[j+][k])*(j!=two)%mod + 1ll*f[i-][j][k+]*(v[j][k]-v[j][k+])*(k!=three)%mod )%mod;
printf("%d",f[n][][]);
return ;
}
推荐比如说这个xiongdi的代码
https://codeforces.com/contest/1174/submission/56391704
超内存的代码
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e6+; /*
dp题
检查:
1.认真检查公式
2.认真检查代码
3.造一个规模适中的数据
手动推导
对应程序的结果
判断是否相同
*/ ///+1 20->21 2->3
///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
///1e18*k k<=9
ll f[maxn][21][3],v[21][3]; int main()
{
int n,two,three,i,j,k;
scanf("%d",&n);
two=log(n+eps)/log();///+eps
three=(1.0*n/(<<two)>=1.5);
for (i=;i<=two;i++)
for (j=;j<=three;j++)
v[i][j]=n/((<<i)*(j==?:)); f[][two][]=;
if (three==)
f[][two-][]=;
for (i=;i<=n;i++)
for (j=;j<=two;j++)
for (k=;k<=three;k++)
f[i][j][k]=( f[i-][j][k]*(v[j][k]-(i-))*((v[j][k]-(i-))>=)%mod + f[i-][j+][k]*(v[j][k]-v[j+][k])*(j!=two)%mod + f[i-][j][k+]*(v[j][k]-v[j][k+])*(k!=three)%mod )%mod; printf("%lld",f[n][][]);
return ;
}
Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem的更多相关文章
- Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)
题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...
随机推荐
- HashMap循环
1. Map的四种遍历方式下面只是简单介绍各种遍历示例(以HashMap为例),各自优劣会在本文后面进行分析给出结论. (1) for each map.entrySet() Java 1 2 ...
- 通信有连接有消息队列选择boost.asio
通信有连接有消息队列选择boost.asio 连接自主管理 消息队列自主管理
- java中String类的面试题大全含答案
1.下面程序的运行结果是()(选择一项)String str1="hello";String str2=new String("hello");System.o ...
- 基于React Native的跨三端应用架构实践
作者|陈子涵 编辑|覃云 “一次编写, 到处运行”(Write once, run anywhere ) 是很多前端团队孜孜以求的目标.实现这个目标,不但能以最快的速度,将应用推广到各个渠道,而且还能 ...
- ToDoList 增删改查
ToDoList 主要功能 增加数据 删除数据 修改数据 查寻数据渲染页面 1 . HTML页面 <!DOCTYPE html> <html lang="en"& ...
- 自定义solr域中的配置
<!-- IKAnalyzer--> <fieldType name="text_ik" class="solr.TextField"> ...
- 经典排序背包——cf1203F
先把收益为正数的处理掉:策略是挨个扫,扫n遍,碰到能买的就买,然后可以得到一个更新后的r 剩下的就看做是一个背包模型:物品(a,b)表示当背包体积>a时才能装下体积为b的该物品,问最多装几个 无 ...
- 使用HBuilder编辑器进行真机调试运行时提示Waiting for debugger!
在使用HBuilder编辑器创建mui项目进行真机调试的时候,手机总是提示Waiting for debugger! 现在终于找到了解决办法: 手机 设置 -> 开发人员选项 -> USB ...
- Dubbo入门到精通学习笔记(五):持续集成管理平台之sonarqube代码质量管理平台的介绍与安装
文章目录 SonarQube的介绍 SonarQube的安装 安装简介 详细安装过程 详细使用过程 SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质 ...
- Dubbo入门到精通学习笔记(四):持续集成管理平台之Maven私有库和本地库的安装与配置
文章目录 介绍 Maven私有库和本地库的安装与配置 Nexus安装 Nexus 配置(登录后) 介绍 如果构建的Maven项目本地仓库没有对应的依赖包,那么就会去Nexus私服去下载, 那么如果Ne ...