[JSOI2009]瓶子和燃料 BZOJ2257 数学
题目描述
jyy就一直想着尽快回地球,可惜他飞船的燃料不够了。有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换。jyy的飞船上共有 N个瓶子(1<=N<=1000) ,经过协商,火星人只要其中的K 个。
jyy将 K个瓶子交给火星人之后,火星人用它们装一些燃料给 jyy。所有的瓶子都没有刻度,只在瓶口标注了容量,第i个瓶子的容量为Vi(Vi 为整数,并且满足1<=Vi<=1000000000 ) 。火星人比较吝啬,他们并不会把所有的瓶子都装满燃料。他们拿到瓶子后,会跑到燃料库里鼓捣一通,弄出一小点燃料来交差。jyy当然知道他们会来这一手,于是事先了解了火星人鼓捣的具体内容。
火星人在燃料库里只会做如下的3种操作:
- 将某个瓶子装满燃料;
- 将某个瓶子中的燃料全部倒回燃料库;
- 将燃料从瓶子a倒向瓶子b,直到瓶子b满或者瓶子a空。燃料倾倒过程中的损耗可以忽略。
火星人拿出的燃料,当然是这些操作能得到的最小正体积。jyy知道,对于不同的瓶子组合,火星人可能会被迫给出不同体积的燃料。jyy希望找到最优的瓶子组合,使得火星人给出尽量多的燃料。
输入输出格式
输入格式:
第1行:2个整数N,K。
第2..N 行:每行1个整数,第i+1 行的整数为Vi
输出格式:
仅1行,一个整数,表示火星人给出燃料的最大值。
输入输出样例
说明
选择第2 个瓶子和第 个瓶子,火星人被迫会给出4 体积的容量。
讲道理,和我出的趣味赛题一样好吧。。
就两个瓶子为例,最小的自然就是每次不停地相互倒油,最后只剩下gcd(a,b);
那么简单来说就是选K个使得gcd最大!
那就是一道简单题了。。。
当然不能用之前遍历可能因子的方法了,因为 n<=1e9;
那么我们在统计的时候维护一下最大值就ok了;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n, k;
int p[maxn];
map<int, int>Map; int main()
{
//ios::sync_with_stdio(0);
rdint(n); rdint(k);
int maxx = -inf;
int Maxx = -inf;
for (int i = 1; i <= n; i++) {
int x; rdint(x); maxx = max(maxx, x);
for (int j = 1; j <= sqrt(x); j++) {
if (x%j == 0) {
Map[j]++;
if (j*j != x)Map[x / j]++;
if (Map[j] == k)Maxx = max(Maxx, j);
if (Map[x / j] == k)Maxx = max(Maxx, x / j);
}
}
}
int cnt = 0;
cout << Maxx << endl;
return 0;
}
[JSOI2009]瓶子和燃料 BZOJ2257 数学的更多相关文章
- [BZOJ2257][Jsoi2009]瓶子和燃料(数学)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2257 分析: 1.先考虑确定的瓶子下的最小体积是多少 ①假设只有两个瓶子v1,v2,易 ...
- 【BZOJ2257】[JSOI2009]瓶子和燃料(数论)
[BZOJ2257][JSOI2009]瓶子和燃料(数论) 题面 BZOJ 洛谷 题解 很明显就是从\(n\)个数里面选\(K\)个数让他们的\(gcd\)最大. 暴力找所有数的因数,拿个什么东西存一 ...
- bzoj2257 [Jsoi2009]瓶子和燃料 最大公约数
[Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1449 Solved: 889[Submit][Status][Di ...
- bzoj2257: [Jsoi2009]瓶子和燃料
2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MB Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了 ...
- BZOJ 2257: [Jsoi2009]瓶子和燃料 裴蜀定理
2257: [Jsoi2009]瓶子和燃料 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】
2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1326 Solved: 815[Submit][Stat ...
- [BZOJ 2257][JSOI2009]瓶子和燃料 题解(GCD)
[BZOJ 2257][JSOI2009]瓶子和燃料 Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子 ...
- 洛谷 P4571 BZOJ 2257 [JSOI2009]瓶子和燃料
bzoj题目链接 上面hint那里是选择第2个瓶子和第3个瓶子 Time limit 10000 ms Memory limit 131072 kB OS Linux Source Jsoi2009 ...
- 【数学 裴蜀定理】bzoj2257: [Jsoi2009]瓶子和燃料
使gcd最大的trick Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换.jyy的飞船上共有 N ...
随机推荐
- 第三章 Java内存模型(下)
锁的内存语义 中所周知,锁可以让临界区互斥执行.这里将介绍锁的另一个同样重要但常常被忽视的功能:锁的内存语义 锁的释放-获取建立的happens-before关系 锁是Java并发编程中最重要的同步机 ...
- leetcode645
vector<int> findErrorNums(vector<int>& nums) { ; int S[N]; int n = nums.size(); ; i ...
- elastic(7)bulk
转自:https://www.cnblogs.com/xing901022/p/5339419.html bulk批量导入 批量导入可以合并多个操作,比如index,delete,update,cre ...
- Python之路:面向对象及相关
其他相关 一.isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 class Foo(object): pass obj = Foo() isinstan ...
- if __name__ == "__main__": 的使用
#!/usr/bin/env python from qq.lib.a2 import register from qq.lib.a3 import login def main(): while T ...
- C/C++读写csv文件
博客转载自:http://blog.csdn.net/u012234115/article/details/64465398 C++ 读写CSV文件,注意一下格式即可 #include <ios ...
- Ubuntu14.04文件目录说明
一.Dev设备目录 二.etc配置文件目录 三.bin默认程序安装目录 四.boot系统启动用到的配置文件以及内核镜像 五.home用户目录 六.lib库文件目录 七.media系统自动挂载设备会选择 ...
- Python 使用其他邮件服务商的 SMTP 访问(QQ、网易、163、Google等)发送邮件
163邮箱SMTP授权 使用Python SMTP发送邮件 # -*- coding:utf-8 -*- from __future__ import print_function __author_ ...
- Luogu 4552 [Poetize6] IncDec Sequence
在BZOJ上好像被权限掉了. 考虑差分,定义差分数组$b$ $$b_i = \left\{\begin{matrix} a_i \ \ \ (i == 1)\\ a_i - a_{i - 1}\ \ ...
- Entity Framework Tutorial Basics(13):Database First
Database First development with Entity Framework: We have seen this approach in Create Entity Data M ...