A.Alyona and copybooks
这题考查思维的全面性。
一开始我直接分类推公式,余数不同分类讨论。
AC代码:
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL inf=1e12;
int main(){
LL ans=inf;
LL n,a,b,c;
scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
int k=(int)(n%4);
if(k==0) ans=0;
else if(k==1){
ans=min(ans,3*a);
ans=min(ans,c);
ans=min(ans,a+b);
}
else if(k==2){
ans=min(ans,2*a);
ans=min(ans,b);
ans=min(ans,2*c);
}
else if(k==3){
ans=min(ans,a);
ans=min(ans,b+c);
ans=min(ans,3*c);
}
printf("%lld\n",ans);
return 0;
}
在推完公式,我发现每类书最多买不超过4包,直接三个for循环枚举所有情况。后面想了一下,确实很有道理。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long LL;
const LL inf=1e12;
int main(){
LL n,a,b,c;
while(scanf("%lld%lld%lld%lld",&n,&a,&b,&c)!=EOF){
LL ans=inf;
for(int i=0;i<5;++i)
for(int j=0;j<5;++j)
for(int k=0;k<5;++k){
if((n+i+2*j+3*k)%4==0)
ans=min(ans,i*a+j*b+k*c);
}
cout<<ans<<endl;
}
return 0;
}
如有不当指出欢迎指出!
A.Alyona and copybooks的更多相关文章
- Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)
A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Alyona and copybooks
题目连接 题意: 给 n,a,b,c四个数,n为已有的书的数目,问再买k本书所需花费最少是多少,(k+n)%4==0: 有三种套餐 第一种只有一本书,花费a 第二种有两本书,花费b, 第三种有三本书, ...
- CodeForces 740A Alyona and copybooks
完全背包. 直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了. #pragma comment(linker, "/STACK:1024000000,102400 ...
- Codeforces Round #381 (Div. 2) A B C 水 构造
A. Alyona and copybooks time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #381 (Div. 2) 复习倍增//
刷了这套题 感触良多 我想 感觉上的差一点就是差很多吧 . 每次都差一点 就是差很多了... 不能气馁..要更加努力去填补那一点点. 老天不是在造物弄人,而是希望你用更好的自己去迎接自己. A. ...
- CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK
A.Alyona and copybooks Problems: 给你一个数n和代价分别为a, b, c.数量不限的1, 2, 3,求将n凑成4的倍数的最小代价 Analysis: cj:取个模随便凑 ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
随机推荐
- 流API--流的基础知识
流接口--BaseStream接口 流API定义了几个流接口,这些接口包含在java.util.stream中.BaseStream是基础接口,它定义了所有流都可以使用的基本功能.我们来看一下源码: ...
- shell第一篇
前两天不停的再看内核相关的内容,了解内核的形成.内核的执行流程.内核的作用,结果是舍近求远. 其实我只是想了解一下shell的工作,shell与内核有关,但并不需要我么真正去做什么,至少对于我这样额初 ...
- CentsOS7无网情况下安装mysql5.7
1.需求就不用讲了,客户现场,政府环境,银行环境,大多是没网的,所以无网安装是很有必要的 mysql下载路径:https://dev.mysql.com/downloads/mysql/ 查看自己Li ...
- linux僵尸进程
什么是僵尸进程? 在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / waitpid)他, 那么他将变成一个僵尸进程. 在fork()/execve()过程中,假设子 ...
- JAVA List根据字段排序以及取前几条数据
1.经常会遇到对组装的list排序或提取list中前几条数据,例如: 根据时间排序: list.sort((o1, o2) -> o2.getCreateTime().compareTo(o1. ...
- 在线生成PDF的网站-HTML 转 PDF 在线
http://pdf.df5d.com/ (服务器问题,演示暂停了,但是 下面介绍的组件还是可以使用的) 将前面用到的wkhtmltopdf用一个服务器程序集成在一起,接受一个URL参数,在生成一 ...
- Python CRM项目六
自定义Django Admin的action 在Django Admin中,可以通过action来自定义一些操作,其中默认的action的功能是选中多条数据来进行删除操作 我们在king_admin中 ...
- 16_Python闭包
一.什么是闭包 什么是闭包:内函数对外函数非全局变量的引用,并且外函数的返回值是内函数的引用(地址). def wrapper(): name = 'zhangsan' def inner(): na ...
- datatables里面的search怎么去掉?
今天使用datatables插件的时候,由于需求是把自带的search去掉,并且给输入框加上placeholder="Search",使其看起来更简洁美观,于是乎简单粗暴的把代码改 ...
- dlib下训练自己的物体检测器--手的检测
之前我们在Linux上安装了dlib(http://www.cnblogs.com/take-fetter/p/8318602.html),也成功的完成了之前的人脸检测程序, 今天我们来一起学习怎样使 ...