我先采用了智障解法(n * n枚举...刚开始把n看成1000了还以为能过)

理所当然的t了,不过我怀疑优化一下能过?(感觉数据不太行的亚子

然后就是O(n * k * k)的解法,看到好多人快乐二分,其实完全用不到,建一个10000000的数组就ok了(我刚开始还以为会MLE

不过有几个地方要注意一下

1.要判断是不是在范围内,不然会出现查询的时候越界,快乐re的情况

2.要判断是不是>0,同理,而且负数取模会有你意想不到的结果

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = ;
int a[N];
bool map[];
int main() {
int n, K;
scanf("%d %d", &n, &K);
for (int i = ; i < n; i++)
scanf("%d", &a[i]), map[a[i]] = true;
int q;
scanf("%d", &q);
while (q--) {
int s;
scanf("%d", &s);
int ans = K + ;
for (int i = ; i < n; i++)
for (int j = ; j <= K; j++)
for (int k = ; k <= (K - j); k++) {
if ((s - j * a[i]) % k != || s <= j * a[i])
continue;
if ((s - j * a[i]) / k > a[n - ])
continue;
if (map[(s - j * a[i]) / k])
ans = min(ans, j + k);
}
if (ans <= K)
printf("%d\n", ans);
else
puts("-1");
}
return ;
}

Codeforces 524C.The Art of Dealing with ATM(暴力)的更多相关文章

  1. CodeForces 524C The Art of Dealing with ATM (二分)

    题意:给定 n 种不同的钞票,然后用q个询问,问你用最多k张,最多两种不同的钞票能不能组成一个值. 析:首先如果要求的值小点,就可以用DP,但是太大了,所以我们考虑一共最多有n * k种钞票,如果每次 ...

  2. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  3. codeforce The Art of Dealing with ATM

    题目大意 ATM取款机有n种不同的钱币kind[i],每次取款允许吐出不超过k张钱币,且钱币的种类数不能超过2(一开始没理解2的意思),现在有q次取款,钱数为ques,问ATM能否凑出这样的钱,若能的 ...

  4. cf524C The Art of Dealing with ATM

    ATMs of a well-known bank of a small country are arranged so that they can not give any amount of mo ...

  5. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  6. Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力

    C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...

  7. Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力

    B. HDD is Outdated Technology 题目连接: http://www.codeforces.com/contest/612/problem/B Description HDD ...

  8. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  9. Educational Codeforces Round 1 B. Queries on a String 暴力

    B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/59 ...

随机推荐

  1. Excel——排序筛选

    1,自定义排序:多个关键字,从右向左一一排序 * 按颜色排序 * 按自定义序列排序 *两列中,列一个中间数,升序 * 打印标题行 * 选中,定位条件(可见),选择 * 数值筛选(大于等于),文本筛选( ...

  2. XSS跨站测试代码

    '><script>alert(document.cookie)</script>='><script>alert(document.cookie)&l ...

  3. 已发布的WEB项目,如何挂在服务器或者本机的IIS下

    第一步:打开IIS,在打开的IIS中,右击 “Default Web Site”,在弹出对话框中选择“新增应用程式”,参照如下图,设置相应参数. 第二步:在已经发布的项目文件系统添加在站点下后,点击项 ...

  4. opencv —— line、ellipse、rectangle、circle、fillPoly、putText 基本图形的绘制

    绘制线段:line 函数 void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, ...

  5. vulnhub靶机之DC6实战(wordpress+nmap提权)

    0x00环境 dc6靶机下载地址:https://download.vulnhub.com/dc/DC-6.zip dc6以nat模式在vmware上打开 kali2019以nat模式启动,ip地址为 ...

  6. 【新人赛】阿里云恶意程序检测 -- 实践记录11.3 - n-gram模型调参

    主要工作 本周主要是跑了下n-gram模型,并调了下参数.大概看了几篇论文,有几个处理方法不错,准备下周代码实现一下. xgboost参数设置为: param = {'max_depth': 6, ' ...

  7. 01、模拟ATM机界面程序

    一.概述 设计一个简单的模拟自动取款机ATM界面的程序,实现用户登录及取款等功能. 二.需求分析 (1)模拟自动取款机ATM界面,有常用功能. (2)主要功能包括;用户输入密码登录主界面.取款功能.取 ...

  8. Mac 配置本地SSL

    1,执行: && openssl req -new -sha256 -x509 -days -key server.key -out server.crt 2,生成过程中,其它可随便填 ...

  9. Java 日期格式化,Java 日期工具类,Java Date工具类

    ================================ ©Copyright 蕃薯耀 2020-01-19 https://www.cnblogs.com/fanshuyao/ import ...

  10. 42.通过原生SQL语句进行操纵mysql数据库

    views.py文件中: from django.shortcuts import render # 导入connection模块 from django.db import connection d ...