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 ---- ...
随机推荐
- vm Linux centos 链接外网
修改network配置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 修改ONBOOT=yes 重启服务 service network restart ...
- 13-jQuery的ajax
什么是ajax AJAX = 异步的javascript和XML(Asynchronous Javascript and XML) 简言之,在不重载整个网页的情况下,AJAX通过后台加载数据,并在网页 ...
- 使用vlc打开usb摄像头
打开vlc播放器 可以打开网络串流的方式打开摄像头,但只支持第一个摄像头 这一串地址拼凑方法看下面,下面可以选择摄像头 为什么只支持第一个摄像头可以参考下一篇使用Vlc.DotNet打开摄像头并截图 ...
- 关于访问Jira和Confluence服务越来越缓慢的解决办法阐述
Jira和Confluence部署在同一台服务器上,跑一段时间后,发现访问jira和confluence时,打开越来越缓慢.这是因为根据主机物理内存不同,默认的java虚拟机内存也会不同(一个较低值) ...
- BIOS翻译
BIOS翻译 BIOS(Basic Input/Output System—基本输入输出系统).BIOS可以视为是一个永久地记录在ROM中的一个软件 Main主要信息 :main 主要信息 advan ...
- git && gitlab 使用
安装略过 使用 基于公钥的认证登录,方便对用户进行权限控制 useradd -s /usr/bin/git-shell testgit #创建一个用户 或者直接useradd testgit 然后去/ ...
- GDB使用记录
ref:http://sunyongfeng.com/201506/programmer/tools/gdb.html 简介 GDB,GNU Debugger,特性如下: GDB具备各种调试功效,可对 ...
- 如何实现Python调用C代码--python与C之间如何通信(swig)
转载: https://www.zhihu.com/question/23003213 1. C代码如何调用Python 1.1 test #include <Python.h> int ...
- springBoot总结
springBoot总结: ssm基本的依赖: <dependencies> <!--添加依赖thymeleaf 可以访问html页面--> <!--<depend ...
- react-router v4 按需加载的配置方法
在react项目开发中,当访问默认页面时会一次性请求所有的js资源,这会大大影响页面的加载速度和用户体验.所以添加按需加载功能是必要的,以下是配置按需加载的方法: 安装bundle-loader np ...