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 ...
随机推荐
- 在CMainFrame里使用定时器是有讲究的
设置定时器函数:SetTimer 单位毫秒 销毁定时器函数:KillTimer 消息:WM_TIMER 注意事项: (1)不要在构造函数里设置定时器. (2)不要在析构函数里销毁定时器. 原因:构造函 ...
- Hibernate (一)
1 JDBC的优缺点 优点: 直接底层操作,提供了简单.便捷的访问数据库的方法,跨平台比较强. 灵活性比较强,可以写复杂的SQL. 缺点: JDBC没有做到面向对象的编程,使得程序员的思考还停留在SQ ...
- GitHub For Beginners: Don’t Get Scared, Get Started
It's 2013, and there's no way around it: you need to learn how to use GitHub.2 Why? Because it's a s ...
- Func常用模块及API
Func常用模块及API Func提供了非常丰富的功能模块,包括: CommandModule(执行命令) CopyFileModule(拷贝文件) CpuModule(CPU信息) DiskModu ...
- 忽略node.js服务中favicon.icon的请求
场景 一个最简单的node.js的http服务 const http = require('http'); const server = http.createServer(function(req, ...
- java之过滤器Filter
Java三大器之过滤器(Filter)的工作原理和代码演示 一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术之一,WEB开发人员通过Filter技术,对w ...
- phpstorm中使用xdebug配置cli模式的调试
这里略去xdebug的安装,安装很简单可以下载源码包,动态编译进去! 环境: Dev 服务器(IP:192.168.2.100),安装phpstorm,用来做开发任务! Server服务器(IP:19 ...
- [Sdoi2017]相关分析 [线段树]
[Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...
- 51Nod 欢乐手速场1 A Pinball[DP 线段树]
Pinball xfause (命题人) 基准时间限制:1 秒 空间限制:262144 KB 分值: 20 Pinball的游戏界面由m+2行.n列组成.第一行在顶端.一个球会从第一行的某一列出发 ...
- SDN第一次上机作业
作业链接 用字符命令生成拓扑,并测试连通性,截图 sudo mn --topo tree,fanout=3,depth=2 用可视化界面生成拓扑,并测试连通性,截图 用Python脚本生成一个Fat- ...