Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]
PROBLEM D - Round Subset
题
OvO http://codeforces.com/contest/837/problem/D
837D
解
DP,
dp[i][j]代表已经选择了i个元素,当2的个数为j的时候5的个数的最大值
得注意最大值(貌似因为这个喵呜了一大片喵~☆)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; typedef long long ll; const int M=64*202;
const int N=M-2; int n,k;
int f[222][M]; //f[i][j] used num=i, sum of k2=j, val of f[i][j] = max sum of k5
int k2[222],k5[222]; void init()
{
memset(k2,0,sizeof(k2));
memset(k5,0,sizeof(k5));
memset(f,-1,sizeof(f));
} int main()
{
int i,j,t;
ll tmp;
cin>>n>>k;
init();
for(i=1;i<=n;i++)
{
scanf("%I64d",&tmp);
while(tmp%2==0)
tmp/=2,k2[i]++;
while(tmp%5==0)
tmp/=5,k5[i]++;
}
f[0][0]=0;
for(i=1;i<=n;i++)
for(j=k;j>=1;j--)
for(t=N;t>=k2[i];t--)
if(f[j-1][t-k2[i]]!=-1)
f[j][t]=max(f[j][t],f[j-1][t-k2[i]]+k5[i]);
int ans=0;
for(t=0;t<=N;t++)
ans=max(ans,min(t,f[k][t]));
cout<<ans<<endl;
return 0;
}
PROBLEM E - Round Subset
题
OvO http://codeforces.com/contest/837/problem/E
837E
解
当B和A公约数不为1的时候(开始的时候,或者B减了一定次数1的时候),就相当于A和B同除以gcd(A,B),然后B继续一次减1。
这样只要每次计算出每次B要减多少次1才能和A有不为1的公约数。
那么预处理出A的质因数,然后每次对A的质因数判断一下,哪个最近(也就是模最小)即可。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; typedef long long ll; const ll M=1e6+44;
const ll inf=1e18; ll A,B;
ll prim[M];
ll lp,nump[M];
ll ans; void init(ll spl)
{
ll i,j;
lp=0;
for(i=2;i*i<=spl;i++)
if(spl%i==0)
{
prim[++lp]=i;
nump[lp]=0;
while(spl%i==0)
spl/=i,nump[lp]++;
}
if(spl!=1)
{
prim[++lp]=spl;
nump[lp]=1;
}
} void deal()
{
if(B==0)
return ;
if(A==1)
{
ans+=B;
return ;
}
ll i,j,mn;
ll tmp,gcd;
mn=inf;
for(i=1;i<=lp;i++)
{
tmp=B%prim[i];
if(tmp<mn)
mn=tmp;
}
tmp=mn;
ans+=tmp;
B-=tmp;
gcd=__gcd(A,B);
A/=gcd; B/=gcd;
for(i=1;i<=lp;i++)
if(gcd%prim[i]==0)
{
while(gcd%prim[i]==0)
gcd/=prim[i],nump[i]--;
if(nump[i]==0)
{
swap(nump[i],nump[lp]);
swap(prim[i],prim[lp]);
lp--; i--;
}
}
deal();
} void solve()
{
ans=0;
deal();
printf("%I64d\n",ans);
} int main()
{
scanf("%I64d%I64d",&A,&B);
init(A);
solve();
return 0;
}
PROBLEM F - Prefix Sums
题
OvO http://codeforces.com/contest/837/problem/F
837F
解
由于新生成的m+1个数列第一个肯定为0,所以可以忽略掉,当作每次新生成的数列只拥有m个元素
然后 举个栗子
当s={1,0,0,0,0} 可以得到如下矩阵

显然这拥有某神秘三角的性质
然后二分答案,每次通过组合数来算就行了,由于太大直接退出,所以不会超时(如果C(p,q),p-q<q的话,转化为C(p,p-q))
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio> using namespace std; typedef long long ll; const ll M=2e5+44; ll n,k;
ll sum;
ll s[M]; bool check(ll spl)
{
ll i,j,t,x,y,p,q;
double sum=0,tmp;
for(t=0;t<n;t++)
{
if(s[t]==0) continue;
x=spl; y=(n-1)-t; //s[i]*c(y+x-1,x-1)
p=x-1; q=x+y-1; //c(q,p)
p=min(q-p,p);
tmp=s[t];
for(i=q,j=p;j>=1;j--,i--)
{
tmp=tmp*i/j;
if(tmp>=k)
return true;
}
sum+=tmp;
if(sum>=k) return true;
}
return false;
} void solve()
{
ll li=0,ri=k,mid;
while(li<ri-1)
{
// cout<<li<<' '<<ri<<endl;
mid=(li+ri)>>1;
if(check(mid))
ri=mid;
else
li=mid;
}
cout<<ri<<endl;
} int main()
{
ll i,j,tmp;
cin>>n>>k;
for(i=0;i<n;i++)
{
scanf("%I64d",&s[i]);
if(s[i]>=k)
{
printf("0\n");
return 0;
}
}
solve();
return 0;
}
Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]的更多相关文章
- 【动态规划】【滚动数组】Educational Codeforces Round 26 D. Round Subset
给你n个数,让你任选K个,使得它们乘起来以后结尾的0最多. 将每个数的因子2和因子5的数量求出来,记作a[i]和b[i]. 答案就是max{ min{Σa[i],Σb[i]} }(a[i],b[i]是 ...
- Educational Codeforces Round 26 F. Prefix Sums 二分,组合数
题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
随机推荐
- 数据检索grep
linux操作中,总是会输出很多的内容.但是有些内容并不是我们重点关注的,所以为了看起来方便,也为了提升效率,就将不需要的内容过滤掉. 只输出想要的东西. grep: 用于搜索 模式参数(给定的字符 ...
- Treasure Island(两遍dfs)-- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
题意:https://codeforc.es/contest/1214/problem/D 给你一个n*m的图,每次可以往右或者往下走,问你使(1,1)不能到(n,m)最少要放多少 ‘ # ’ . 思 ...
- django form组件 cookies,session
django form组件 渲染标签 就是组件里面的字段在前端展示叫做渲染标签 校验数据 用户输入的数据提交给后端组件叫做校验数据 forms组件中定义的字段都是必须传值的(required=Tr ...
- Elasticsearch多集群数据同步
有时多个Elasticsearch集群避免不了要同步数据,网上查找了下数据同步工具还挺多,比较常用的有:elasticserach-dump.elasticsearch-exporter.logsta ...
- python内置函数0-1
# a=bool(None)# print(a) class Foo: def __repr__(self): return 'bbbbbbb'f = Foo()ret = ascii(f)print ...
- Android获取网络时间的方法
一.通过免费或者收费的API接口获取 1.免费 QQ:http://cgi.im.qq.com/cgi-bin/cgi_svrtime 淘宝:http://api.m.taobao.com/rest/ ...
- C# 操作地址 从内存中读取写入数据(初级)
本示例以植物大战僵尸为例, 实现功能为 每1秒让阳光刷新为 9999.本示例使用的游戏版本为 [植物大战僵尸2010年度版], 使用的辅助查看内存地址的工具是 CE. 由于每次启动游戏, 游戏中阳光 ...
- luogu题解P4198楼房重建--线段树神操作
题目链接 https://www.luogu.org/problemnew/show/P4198 分析 一句话题意,一条数轴上有若干楼房,坐标为\(xi\)的楼房有高度\(hi\),那么它的斜率为\( ...
- 解决 Ubuntu 19 安装openjdk 8后与openjfx不兼容
小淘气放假了,孩子在上幼儿园的小朋友,报班也不能太变态嘛, 还是让他自己娱乐的时间多一点,但是现在在家的娱乐就是看电视,听说电视看多了越看越傻,就想方设法的给他找一点娱乐活动,把我闲置的树莓派给他装了 ...
- Express bodyParser中间件使用方式
bodyParser中间件用来解析http请求体,是express默认使用的中间件之一. 1.这个模块提供以下解析器 (1) JSON body parser (2) Raw body parser ...