这题考查思维的全面性。

一开始我直接分类推公式,余数不同分类讨论。

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的更多相关文章

  1. 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 ...

  2. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  3. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. Alyona and copybooks

    题目连接 题意: 给 n,a,b,c四个数,n为已有的书的数目,问再买k本书所需花费最少是多少,(k+n)%4==0: 有三种套餐 第一种只有一本书,花费a 第二种有两本书,花费b, 第三种有三本书, ...

  5. CodeForces 740A Alyona and copybooks

    完全背包. 直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了. #pragma comment(linker, "/STACK:1024000000,102400 ...

  6. 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 ...

  7. Codeforces Round #381 (Div. 2) 复习倍增//

    刷了这套题  感触良多 我想 感觉上的差一点就是差很多吧 . 每次都差一点  就是差很多了... 不能气馁..要更加努力去填补那一点点.  老天不是在造物弄人,而是希望你用更好的自己去迎接自己. A. ...

  8. CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK

    A.Alyona and copybooks Problems: 给你一个数n和代价分别为a, b, c.数量不限的1, 2, 3,求将n凑成4的倍数的最小代价 Analysis: cj:取个模随便凑 ...

  9. 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 ...

随机推荐

  1. python_面向对象

    什么是面向对象? -- 一种主流编程范式,编程思维框架,世界主流两个方向,面向对象和面向过程. --  面向是把关注点集中一个具体东西,比如看向手机,也叫面向手机,手机就是一个对象,我们 把手机的属性 ...

  2. 理解maven的核心概念

    原文出处:http://www.cnblogs.com/holbrook/archive/2012/12/24/2830519.html 好久没进行java方面的开发了,最近又完成了一个java相关的 ...

  3. Ubuntu 安装 Nginx 实现反向代理

    安装Nginx依赖库(ubuntu平台) 最近域名通过了备案, 想着应用总不能带着端口号访问吧, 于是在网上踩了很多坑, 终于找到了一步直达的方法,起码这一次很顺利的实现了 安装gcc g++的依赖库 ...

  4. Struts2是什么?

    Struts2是什么: Struts2是整合了struts1和webwork的技术优点的使用广泛的MVC框架: Struts2的特点: 1.基于MVC框架,结构清晰,便于开发人员掌控开发流程: 2.使 ...

  5. HTML——filedset和legend标签

    1.<filedset>定义围绕表单中元素的边框. 2.legend 元素表示作为 legend 元素的父元素的 fieldset 元素的其余内容的标题(caption). 使用案例: & ...

  6. AQS 框架之 Unsafe 源码详解

    ■ 前言 之前 LockSupport那篇已经叙述了是线程阻塞工具类,其底层由 Unsafe 实现,即 park(), unpark() 方法,获取指针偏移量,并操纵内存.本篇主要介绍 Unsafe ...

  7. VUE2.0增删改查附编辑添加model(弹框)组件共用

    Vue实战篇(增删改查附编辑添加model(弹框)组件共用) 前言 最近一直在学习Vue,发现一份crud不错的源码 预览链接 https://taylorchen709.github.io/vue- ...

  8. BZOJ 4176: Lucas的数论 [杜教筛]

    4176: Lucas的数论 题意:求\(\sum_{i=1}^n \sum_{j=1}^n \sigma_0(ij)\) \(n \le 10^9\) 代入\(\sigma_0(nm)=\sum_{ ...

  9. BZOJ 3781: 小B的询问 [莫队]

    求区间每种颜色出现次数平方和 写裸题练手 #include <iostream> #include <cstdio> #include <algorithm> #i ...

  10. 2018/2/5 ELK技术栈之ElasticSearch学习笔记

    npm config set registry https://registry.npm.taobao.org npm config get registry 支持跨域访问http.cors.enab ...