Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit
Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit
https://code.google.com/codejam/contest/351101/dashboard#s=p0
Problem
You receive a credit C
at a local store and would like to buy two items. You first walk through the store and create a list L
of all available items. From this list you would like to buy two items that add up to the entire value of the credit. The solution you provide will consist of the two integers indicating the positions of the items in your list (smaller number first).
Input
The first line of input gives the number of cases, N. N test cases follow. For each test case there will be:
- One line containing the value C, the amount of credit you have at the store.
- One line containing the value I, the number of items in the store.
- One line containing a space separated list of I integers. Each integer P indicates the price of an item in the store.
- Each test case will have exactly one solution.
Output
For each test case, output one line containing "Case #x: " followed by the indices of the two items whose price adds up to the store credit. The lower index should be output first.
Limits
5 ≤ C ≤ 1000
1 ≤ P ≤ 1000
Small dataset
N = 10
3 ≤ I ≤ 100
Large dataset
N = 50
3 ≤ I ≤ 2000
Sample
Input | Output |
3 |
Case #1: 2 3 |
Solution:
vector<int> solve1(double C, double item_n, vector<int>price)
{ map<int, int> price_existance;
for (int i = ; i < item_n; i++) {
price_existance[price[i]] = i;
} for (int i = ; i < item_n; i++) {
if (price_existance.count(C - price[i])) {
int index0 = price_existance.at(C - price[i]); if (index0 == i)
continue; vector<int> result;
if (i > index0) {
result.push_back(index0 + );
result.push_back(i + );
return result;
} else {
result.push_back(i + );
result.push_back(index0 + );
return result;
}
}
}
return vector<int>();
} int main() {
freopen("in", "r", stdin);
freopen("out", "w", stdout); int t_case_num;
scanf("%d", &t_case_num);
if (!t_case_num) {
cerr << "Check input!" << endl;
exit();
} // Read input set
int C, item_n;
for (int case_n = ; case_n <= t_case_num; case_n++) {
scanf("%d", &C);
scanf("%d", &item_n);
vector<int>price; for (int i = ; i < item_n; i++) {
int p = ;
cin >> p;
price.push_back(p);
} auto result = solve1(C, item_n, price);
printf("Case #%d: %d %d\n", case_n, result[], result[]);
} fclose(stdin);
fclose(stdout);
return ;
}
Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit的更多相关文章
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- Google APAC----Africa 2010, Qualification Round(Problem A. Store Credit)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p0 问题描述: Problem You receive a cre ...
- Google APAC----Africa 2010, Qualification Round(Problem C. T9 Spelling)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p2 问题描述: Problem The Latin alphabe ...
- Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p1 问题描述: Problem Given a list of s ...
- Google Code Jam 第一题
通过的第一题,留做纪念,呵呵,非常简单,Africa 2010, Qualification Round: Store Credit. #include <stdio.h> #includ ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha
Problem B. Cookie Clicker Alpha Introduction Cookie Clicker is a Javascript game by Orteil, where ...
- [Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
随机推荐
- 47、求1+2+3+...+n
一.题目 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 二.解法 public class Solut ...
- 45.Jump Game II---贪心---2018大疆笔试题
题目链接 题目大意:与55题类似,只是这里要求出跳数. 法一(借鉴):贪心.cur表示当前能到达的最远距离,pre表示上一次能到达的最远距离,每到一个位置更新一次最远距离cur,如果当前位置超过了上一 ...
- git 还原到指定版本号
git clone git branch -r --contains 88b92060224e96ef209565fa75c816eb9b0fae8e git checkout origin/re ...
- Python实现好友全头像的拼接
微信好友全头像 话不多说,直接上代码 import itchat import math import PIL.Image as Image import os itchat.auto_login() ...
- 《深入理解Java虚拟机》笔记--第三章 、垃圾收集器与内存分配策略
1960年诞生于MIT的Lisp是第一门真正使用内存动态分配和垃圾收集技术的语言. Java的垃圾收集(Garbage Collection)主要关注堆和方法区的内存回收. 在GC堆进行回收前,第一件 ...
- [会装]Hive安装(基于mysql数据库)
环境信息:Mac 安装步骤: 1. 下载hive组件(我选择的是社区的2.0.1版本) http://apache.mirror.globo.tech/hive/hive-2.0.1/ 2. 下载my ...
- LAMP网站架构解释
对于大流量.大并发量的网站系统架构来说,除了硬件上使用高 性能的服务器.负载均衡.CDN等之外,在软件架构上需要重点关注下面几个环节:使用高性能的操作系统(OS).高性能的网页服务器(Web Serv ...
- HTTPS握手过程
HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密.具体是如何进行加密,解密,验证的,且看下图,下面的称为一次握手. 1. 客户端发起HT ...
- 创建 dblink
目的:oracle中跨数据库查询 两台数据库服务器db_A(本地)和db_B(远程192.168.1.100),db_A下用户user_a 需要访问到db_B下user_b的数据解决:查询 ...
- ios app应用在显示屏幕上改中文名
1.点击项目名 2.选Build settings 搜索 product name 3.双击,改为需要在手机上显示的应用名