2257: [Jsoi2009]瓶子和燃料
来源:互联网 发布:淘宝虚拟现实vr购物 编辑:程序博客网 时间:2024/05/16 01:01
题目链接
题目大意:给定n个瓶子,选择k个,可以随便倒油,问最大化选择k个瓶子可以倒出的油数量的最小值
题解:我拿两个瓶子YY了一下,以为是取模……好吧,大概类似于辗转相减,所以对两个瓶子,答案为gcd(x,y)
由裴蜀定理,若干整数的线性组合一定为它们gcd的倍数,且存在一组解为gcd
于是问题变成了n个数中选k个,最大化gcd
对每个数分解因数,找最大且出现至少k次的因数即可
我的收获: 裴蜀定理应用……
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std; int n,k,tot,res,x,cnt[1000005]; void fj(int x){ int i; for(i=1;i*i<=x;i++) if(x%i==0) cnt[++tot]=i,cnt[++tot]=x/i; if(i*i==x) cnt[++tot]=i;//特判…… } void work(){ for(int i=tot;i;i--){ if(cnt[i]!=cnt[i+1]) res=0; res++; if(res==k){printf("%d\n",cnt[i]);break;} }} void init(){ cin>>n>>k; for(int i=1;i<=n;i++) scanf("%d",&x),fj(x); sort(cnt+1,cnt+1+tot);} int main(){ init(); work(); return 0;}
阅读全文
0 0
- 2257: [Jsoi2009]瓶子和燃料
- 2257: [Jsoi2009]瓶子和燃料
- 2257: [Jsoi2009]瓶子和燃料
- BZOJ 2257 JSOI2009 瓶子和燃料 数论
- BZOJ 2257 [Jsoi2009]瓶子和燃料
- BZOJ 2257: [Jsoi2009]瓶子和燃料
- BZOJ 2257 [Jsoi2009] 瓶子和燃料
- bzoj 2257: [Jsoi2009]瓶子和燃料
- bzoj 2257: [Jsoi2009]瓶子和燃料
- BZOJ 2257: [Jsoi2009]瓶子和燃料 数论
- [BZOJ2257][Jsoi2009]瓶子和燃料
- BZOJ2257: [Jsoi2009]瓶子和燃料
- bzoj2257 [Jsoi2009]瓶子和燃料
- bzoj2257: [Jsoi2009]瓶子和燃料
- 【bzoj2257】【JSOI2009】瓶子和燃料
- bzoj 2257: [Jsoi2009]瓶子和燃料 裴蜀定理
- bzoj 2257: [Jsoi2009]瓶子和燃料 (gcd+map)
- bzoj 2257: [Jsoi2009]瓶子和燃料(裴蜀定理)
- 字符编码 ASCII,Unicode和UTF-8的关系
- 记录我的caffe2 vs2017安装过程
- CSU 1101: 报数游戏(水题)
- 【Spring】Spring MVC原理及配置详解
- 区块链解读2
- 2257: [Jsoi2009]瓶子和燃料
- 1754:字符串数组排序问题(4.1算法之排序和算法性能)
- Shiro授权详细解析
- Android打造流畅九宫格抽奖
- MapReduce运行模式-本地模式配置
- 将大数据写入数据库
- Shiro几大拦截器
- 关于闭包
- bzoj 1552: [Cerc2007]robotic sort && bzoj 3506: [Cqoi2014]排序机械臂(splay区间翻转)