思路:

1、暴力枚举每种面值的张数,将可以花光的钱记录下来。每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的。时间复杂度O(n)

2、350 = 200 + 150,买350的道具可用一个150和200的代替,那么直接考虑200和150的道具即可。首先全部买150的道具,剩下的金额为x,可以看成t = x / 50张50的钱加上r = x % 50的钱。如果t <= n / 150,那么说明这些50的都可以和一个150的买200的道具,否则会剩下一些50的没法用。假设最后剩余k张50,那么小费就是50 * k + t. 时间复杂度O(1)

第一种方法AC代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 10000 + 5;
int a[maxn];
int u[] = {150, 200, 350};
void init() {
	memset(a, 0, sizeof(a));
	for(int i = 0; i < 70; ++i)
		for(int j = 0; j < 55; ++j)
			for(int k = 0; k < 30; ++k) {
				int sum = i * 150 + j * 200 + k * 350;
				if(sum > 10000) continue;
				else a[sum] = 1;
			}
}
int find(int n) {
	if(a[n]) return 0;
	//left
	int ans = n;
	for(int i = n-1; i >= 0; --i) {
		if(a[i]) {
			ans = n - i;
			break;
		}
	}
	return ans;
}
int main() {
	init();
	int n, T;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &n);
		printf("%d\n", find(n));
	}
	return 0;
}

第二种方法AC代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1e4 + 5;

int main() {
	int T, n;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &n);
		int u = n % 150, v = n / 150;
		if(u == 0) printf("0\n");
		else {
			int k = u / 50, h = u % 50;
			printf("%d\n", h + 50 * (k - min(v, k)));
		}
	}
	return 0;
}

如有不当之处欢迎指出!

HDU - 1248 寒冰王座 数学or暴力枚举的更多相关文章

  1. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  2. HDU 1248 寒冰王座 (完全背包)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1248 寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    M ...

  3. HDU 1248寒冰王座-全然背包或记忆化搜索

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  4. hdu 1248 寒冰王座(暴力)

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. HDU 1248 寒冰王座(完全背包裸题)

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. HDU 1248 寒冰王座 (水题的N种做法!)(含完全背包)

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. HDU 1248 寒冰王座(完全背包问题另类解法)

    寒冰王座 Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店 ...

  8. HDU 1248 寒冰王座(完全背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 商店里只有三种物品,价格分别为150,200,350.输入钱并计算浪费的钱的最小值,商店不找零. ...

  9. HDU 1248 寒冰王座 完全背包

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1248 中文题,大意就不说了. 第一道完全背包题,跟着背包九讲做的. 和0-1背包的区别在于所不同的是每种 ...

随机推荐

  1. 02-创建 TLS CA证书及密钥

    创建 TLS CA证书及密钥 kubernetes 系统的各组件需要使用 TLS 证书对通信进行加密,本文档使用 CloudFlare 的 PKI 工具集 cfssl 来生成 Certificate ...

  2. 一行代码搭建 Python 静态服务器

    如果电脑上安装有Python, 那么进入到目标文件夹,在终端中运行如下命令, 即可搭建映射当前目录的静态文件服务器: python -m SimpleHTTPServer 9000 默认端口号是800 ...

  3. python _init_学习

    今天继续学习python,接触了_init_,感觉很好玩照着教程手写了一些代码,感觉编程语言是互通的,只是换个了形式来表达 #coding=utf-8#类似于java的构造器class Person: ...

  4. Django的CBV和FBV

    一.FBV FBV(function base views) 就是在视图里使用函数处理请求,也是我们最开始接触和使用的方式,普通项目中最常见的方式. urls.py 1 2 3 4 urlpatter ...

  5. zabbix 安装配置介绍

    200 ? "200px" : this.width)!important;} --> 介绍 Zabbix是一款能够监控各种网络参数以及服务器健康性和完整性的软件.Zabbi ...

  6. Spring MVC Mock demo

    package com.niwodai.mem.web.controller; import com.alibaba.fastjson.JSON; import org.junit.Before; i ...

  7. ubuntu+mono+PetaPoco+Oracle+.net 程序部署

    前言:将windows 下开发的 .net 控制台程序(连接Oracle数据库)部署到 ubuntu 下步骤记录  2017-09-19 实验所用机器为虚拟机Ubuntu16.04  amd64 安装 ...

  8. NIO基础篇(二)

    Selector(选择器)是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样,一个单独的线程可以管理多个channel,从而管理多个网络连接. 传统的 ...

  9. wenpack-simple+elementUI配置

    首先跟着element官方文档走一遍 注意把.babelrc改成这样 { "presets": [ ["env", { "modules": ...

  10. Windows Azure Virtual Machine (34) Azure VM挂载WebDAV

    <Windows Azure Platform 系列文章目录> 之前使用Azure VM,挂载box网盘.发现不能正常挂载,这里简单记录一下. 1.WebDAV的网络映射,需要WebCli ...