思路:

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. python_如何创建可管理的对象属性

    案例: 在面向对象编程中,我们把方法作为对象的接口,自己访问对象的属性可能是不安全的,或设计上不灵活,但是使用调用方法在形式上不如访问属性简洁 繁: circle.getRadius() circle ...

  2. 配置SESSION超时与请求超时

    <!--项目的web.xml中 配置SESSION超时,单位是min.用户在线时间.如果不设置,tomcat下的web.xml的session-timeout为默认.--><sess ...

  3. web项目各个clean

    project clean:清楚tomcat下的已编译的java类.class文件,包括js但不包括jsp server clean:clean tomcat work dictionary:清除to ...

  4. Runtime.addShutdownHook的用法

    原文出处:http://kim-miao.iteye.com/blog/1662550.感谢作者的无私分享. 一.Runtime.addShutdownHook理解 在看别人的代码时,发现其中有这个方 ...

  5. android adapter 中添加OnClickListener事件

    public class SearchAutoAdapter extends BaseAdapter { private OnClickListener mOnClickListener; publi ...

  6. http_build_query()函数使用方法

    http_build_query()函数的作用是使用给出的关联(或下标)数组生成一个经过 URL-encode 的请求字符串. 写法格式:http_build_query ( mixed $query ...

  7. [PHP]接口请求校验的原理

    具体的校验步骤可以自定义,下面是比较直观的一种形式: 1. 客户端:请求参数带上时间,进行首字母排序,连接私钥后,取得加密结果: 客户端请求时带上这个加密结果作为sign参数. 2. 服务端:对sig ...

  8. 关于spring通知中propagation的7种配置《转载》

    <转载>:http://nannan408.iteye.com/blog/1754882

  9. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) :

    在hive命令行创建表时报错: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. ...

  10. 12、SEO工程师指南 - 软件项目角色指南系列文章

    第11章       SEO工程师   SEO工程师是一个比较新兴的职位,在实际的项目管理过程中,SEO工程师的地位相对靠后,只有在项目试运行以及运营期间才能体现出SEO工程师的作用.在项目完成之后, ...