[C++]Store Credit——Google Code Jam Qualification Round Africa 2010

时间:2022-11-09 14:46:30

Google Code Jam Qualification Round Africa 2010 的第一题,很简单。

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

就是找出和正好等于credit的两件商品,套用两个循环就可以解决问题。

#include<iostream>
#include<fstream>
#include<vector> using namespace std; int main(){
ifstream in("A-large-practice.in");
ofstream out("A-large-practice.out");
if (!in){
out << "Open in failde!" << endl;
}
int N;
in >> N;
for (int i = 0; i < N; i++){
int credit;
in >> credit;
int list_size;
in >> list_size;
vector<int> shop_list;
for (int j = 0; j < list_size; j++){
int value;
in >>value;
shop_list.push_back(value);
}
for (int j = 0; j < shop_list.size(); j++){
for (int k = j + 1; k < shop_list.size(); k++){
if (shop_list[j] + shop_list[k] == credit){
out << "Case #" << i + 1 << ": " << j + 1<<" "<< k + 1 << endl;
j = shop_list.size();
break;
}
}
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

[C++]Store Credit——Google Code Jam Qualification Round Africa 2010的更多相关文章

  1. &lbrack;C&plus;&plus;&rsqb;Saving the Universe——Google Code Jam Qualification Round 2008

    Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...

  2. &lbrack;Google Code Jam &lpar;Qualification Round 2014&rpar; &rsqb; B&period; Cookie Clicker Alpha

    Problem B. Cookie Clicker Alpha   Introduction Cookie Clicker is a Javascript game by Orteil, where ...

  3. &lbrack;Google Code Jam &lpar;Qualification Round 2014&rpar; &rsqb; A&period; Magic Trick

    Problem A. Magic Trick Small input6 points You have solved this input set.   Note: To advance to the ...

  4. dp - Google Code jam Qualification Round 2015 --- Problem B&period; Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  5. Google Code jam Qualification Round 2015 --- Problem A&period; Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

  6. Google Code Jam 2014 Round 1 A:Problem C&period; Proper Shuffle

    Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...

  7. Google Code Jam 2016 Round 1B Problem C&period; Technobabble

    题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...

  8. Google Code Jam 2014 Round 1 A:Problem A Charging Chaos

    Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...

  9. Google Code Jam 2016 Round 1C C

    题意:三种物品分别有a b c个(a<=b<=c),现在每种物品各选一个进行组合.要求每种最和最多出现一次.且要求任意两个物品的组合在所有三个物品组合中的出现总次数不能超过n. 要求给出一 ...

随机推荐

  1. &lbrack;Silverlight&rsqb;监听指定控件&lpar;FrameworkElement&rpar;的依赖属性&lpar;DependencyProperty&rpar;的更改

    前言 转载请注明出处:http://www.cnblogs.com/ainijiutian 最近在silverlight项目使用Telerik的控件,遇到一个问题.就是使用RadBusyIndicat ...

  2. 夺命雷公狗ThinkPHP项目之----企业网站25之网站前台面包屑导航URL的完善

    如果想取出面包屑导航的url那么就必须在model层里面进行多取一个了: <?php namespace Home\Model; use Think\Model; class CategoryM ...

  3. 拥抱高效、拥抱 Bugtags 之来自用户的声音

    小编按:这是一篇 Bugtags 用户来稿,主要是介绍了 Bugtags 使用的方法及其带来的效率的提升,谢谢介博同学对 Bugtags 的信赖和支持.小编在这里诚邀各位热心用户向我们投稿,说出你使用 ...

  4. Python:使用threading模块实现多线程编程

    转:http://blog.csdn.net/bravezhe/article/details/8585437 Python:使用threading模块实现多线程编程一[综述] Python这门解释性 ...

  5. c&plus;&plus;程序猿经典面试题

    1.请问i的值会输出什么? #include"iostream.h" int i=1; void main() { int i=i; cout<<i<<en ...

  6. 【原创】ZOJ&lowbar;1649 Rescue 解题报告

    Rescue Time Limit: 2 Seconds      Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...

  7. mahout安装和测试

    Mahout 是 Apache Software Foundation(ASF) 旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发者更加方便快捷地创建智能应用程序.Apac ...

  8. 排序系列 之 快速排序算法 —— Java实现

    基本思想: 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变 ...

  9. VS2015 使用GIT同步到github

    https://www.cnblogs.com/newP/p/5732431.html(参考) 拉取(Pull):将远程版本库合并到本地版本库,相当于(Fetch+Meger) 获取(Fetch):从 ...

  10. http协议和telnet指令讲解

    http协议: 1.http:是网络传输协议:全称为:超文本传输协议: 关系:客户端和服务器的关系: 协议:就是一种规范: 常见的http和https两种,https是http的升级版 http协议: ...