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, NN 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
100
3
5 75 25
200
7
150 24 79 50 88 345 3
8
8
2 1 9 4 4 56 90 3
Case #1: 2 3
Case #2: 1 4
Case #3: 4 5
 

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Google Code Jam 第一题

    通过的第一题,留做纪念,呵呵,非常简单,Africa 2010, Qualification Round: Store Credit. #include <stdio.h> #includ ...

  6. [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 ...

  7. 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 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. 让MySql支持Emoji表情存储

    java后台报错,如下. aused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x84' for column ...

  2. linux c下输入密码不回显

    今天做一个登录程序,需要屏蔽掉密码,于是自己就在网上找资料,找到了一种和linux终端下输入密码方式相同的方法,不显示在终端,具体代码实现如下. #include<stdio.h> #in ...

  3. Native Apps、Web Apps

    Native Apps 指的是远程程序,一般依托于操作系统,有很强的交互,是一个完整的App,可拓展性强,需要用户下载安装使用 优点: 打造完美的用户体验 性能稳定 操作速度快,上手流畅 访问本地资源 ...

  4. c++ primer 2 变量和基本类型

    2.1 基本内置类型 基本内置类型是C++“自带”的类型,区别于标准库定义的类型.使用时不需要应用标准库就可以使用,我们可以理解为数字型有下面这些 整形:就是整数或者是没有小数位的数.它包括bool( ...

  5. 在分享到微信里的网页中,打开qq对话框。

    废话不多说,就是要去这个网址把qq申请一下服务. 网址: http://shang.qq.com/v3/widget.html 大概长这样: 2.截取这一段代码: 3.重新分享到微信,因为微信好像有缓 ...

  6. CentOS7.5下时间戳转换为时间

    Unix时间戳(英文为Unix epoch, Unix time, POSIXme 或 Unix timestamp)是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒 一.查 ...

  7. LoadRunner web_add_header()

    Action() { web_cleanup_cookies(); web_cache_cleanup(); web_url("entrypoint", "URL=htt ...

  8. ref:Adding AFL Bloom Filter to Domato for Fun

    ref:https://www.sigpwn.io/blog/2018/5/13/adding-afl-bloom-filter-to-domato-for-fun Adding AFL Bloom ...

  9. 洛谷P2323 [HNOI2006] 公路修建问题 [二分答案,生成树]

    题目传送门 公路修建问题 题目描述 OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情况还是很糟糕.所以,OIER Associa ...

  10. DP 题集 1

    关于 DP 的一些题目 参考资料 [Tutorial] Non-trivial DP Tricks and Techniques DP Rain and Umbrellas Mr. Kitayuta, ...