这题考查思维的全面性。

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

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. JS中数组的常用方法

    首先,在开始前我们先了解一下什么是数组. 1.什么是数组? 数组就是一组数据的集合,其表现形式就是内存中的一段连续的内存地址,数组名称其实就是连续内存地址的首地址.说白了它就是将一堆数据按照一定的顺序 ...

  2. Linux指令--grep

    原文地址:http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html.感谢作者的无私分享. Linux系统中grep命令是一种强大的文本搜 ...

  3. [Gradle] 在 Eclipse 下利用 gradle 构建系统

      转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 构建系统时候常常要用到 Ant, Maven 等工具,对于初学者 ...

  4. C语言中函数可变参数解析

    大多数时候,函数中形式参数的数目通常是确定的,在调用时要依次给出与形式参数对应的所有实际参数.但在某些情况下希望函数的参数个数可以根据需要确定.典型的例子有 大家熟悉的函数printf().scanf ...

  5. Django环境安装--Django从入门到精通系列教程

    该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...

  6. 交换两个变量的值,不借助第三个变量的 三种方法(JS实现)

    第一种:算术运算法 var a = 10; var b = 12; a = b - a; b = b - a; a = b + a; 它的原理是:把a.b看做数轴上的点,围绕两点间的距离来进行计算.具 ...

  7. event跨进程通信

    event天生的弱势,只有mutex可以感知丢失,就是将另一个进程关闭了,event无法感知. event1: #include <stdio.h> #include <stdlib ...

  8. Python CRM项目三

    1.分页: 分页使用Django内置的分页模块来实现 官方的分页案例 from django.core.paginator import Paginator, EmptyPage, PageNotAn ...

  9. selenium模拟浏览器对搜狗微信文章进行爬取

    在上一篇博客中使用redis所维护的代理池抓取微信文章,开始运行良好,之后运行时总是会报501错误,我用浏览器打开网页又能正常打开,调试了好多次都还是会出错,既然这种方法出错,那就用selenium模 ...

  10. Django中url的生成过程详解

    在前面我们知道,Django启动之前会执行admin.py中的autodiscover()方法. def autodiscover(): autodiscover_modules('admin', r ...