Problem B. Beer Refrigerator
http://codeforces.com/gym/241680/problem/B
比赛的时候考虑的是,它们3个尽可能接近,然后好麻烦,不如暴力枚举,这里不需要质因数分解,而是两重循环枚举所有因数,第3个因数也就随之确定
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int x;
int a[];
int cnt;
int k;
int ans=inf;
int ANS[];
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
freopen("beer.in","r",stdin);
freopen("beer.out","w",stdout);
in(x);
For(i,,x)
if(x%i==)
a[++cnt]=i;
For(i,,cnt)
For(j,,cnt){
k=x/a[i]/a[j];
if(x!=a[i]*a[j]*k)
continue;
if(ans>a[i]*a[j]+a[i]*k+a[j]*k){
ans=a[i]*a[j]+a[i]*k+a[j]*k;
ANS[]=a[i];
ANS[]=a[j];
ANS[]=k;
}
}
o(ANS[]);p(' ');
o(ANS[]);p(' ');
o(ANS[]);
return ;
}
Problem B. Beer Refrigerator的更多相关文章
- ZOJ 3362 Beer Problem(SPFA费用流应用)
Beer Problem Time Limit: 2 Seconds Memory Limit: 32768 KB Everyone knows that World Finals of A ...
- ZOJ 3362 Beer Problem
Beer Problem Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- ZOJ3362 Beer Problem(最小费用任意流)
题目大概说有n个城市,由m条无向边相连,每条边每天最多运送cap桶酒且其运送一桶的花费是cost.现在从1号城市开始出发运酒,供应到2到n号城市,这些城市的收购单价是price,问最大的盈利是多少. ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- poj-3056 http://poj.org/problem?id=3056
http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS Memory Limit: 65536K Tot ...
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
- 算法之路 level 01 problem set
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
- POJ:2695-The Pilots Brothers' refrigerator
题目链接:http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limi ...
- poj2965 The Pilots Brothers' refrigerator(直接计算或枚举Enum+dfs)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://poj.org/problem? id=2965 ---- ...
随机推荐
- pgsql事务与并发控制
事务与并发控制 事务的基本的概念和性质 ACID: 原子性:一个事务要么全部执行,要么全部不执行 一致性:执行事务的时候,数据库从一个一致的状态变更到另一个状态 隔离性: 确保在并发执行的时候,每个事 ...
- Loj #528. 「LibreOJ β Round #4」求和 (莫比乌斯反演)
题目链接:https://loj.ac/problem/528 题目:给定两个正整数N,M,你需要计算ΣΣu(gcd(i,j))^2 mod 998244353 ,其中i属于[1,N],j属于[1,M ...
- 如何取消Paypal自动付款功能
在国外在线服务消费肯定会常遇到PayPal的支付方式,有些人可能PayPal有些余额可能会用这个工具来支付,但付款后,可能服务因为不满意而退掉,但第二年却自动续约了?但明明服务已退掉,这该怎么处理呢? ...
- Gym - 101350F Monkeying Around(线段树+树状数组)
When the monkey professor leaves his class for a short time, all the monkeys go bananas. N monkeys a ...
- app升级注意事项version
1.每次升级生成apk前,修改versionName: 位置: 2.修改数据库表中对应version字段与之对应: 3.出现waiting for debugger,要重启手机: 5.解析包错误,是a ...
- codeforces-1141 (div3)
A.算2,3的因子个数即可 #include <map> #include <set> #include <ctime> #include <cmath> ...
- Numpy系列(三)- 基本运算操作
Numpy 中数组上的算术运算符使用元素级别.最后的结果使用新的一个数组来返回. import numpy as np a = np.array( [20,30,40,50] ) b = np.ara ...
- swiper常见问题
swiper是一个比较不错的一个轮播插件,但是呢,有时候在使用的时候也会出现很多的问题,我将我遇到的一些问题解决办法写在下面. 第一个问题:swiper分页器不显示 一般swiper使用分页器都是这样 ...
- SQLMAP注入教程-11种常见SQLMAP使用方法详解
sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...
- django - 总结 - admin
admin组件,一旦我们注册了表以后,会自动生成很多url,那他是如何添加的呢, 因为admin在启动后会自动执行每个app下的ready方法: 具体是由 from django.utils.modu ...