[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 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 |
就是找出和正好等于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的更多相关文章
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
- [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 ...
- dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
Problem B. Infinite House of Pancakes Problem's Link: https://code.google.com/codejam/contest/6224 ...
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
Problem A. Standing Ovation Problem's Link: https://code.google.com/codejam/contest/6224486/dashbo ...
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- Google Code Jam 2016 Round 1B Problem C. Technobabble
题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...
- 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 ...
- Google Code Jam 2016 Round 1C C
题意:三种物品分别有a b c个(a<=b<=c),现在每种物品各选一个进行组合.要求每种最和最多出现一次.且要求任意两个物品的组合在所有三个物品组合中的出现总次数不能超过n. 要求给出一 ...
随机推荐
- iOS多线程的基本使用
一.NSThread: 程序就是一段代码,是静态的概念 进程是运行起来的程序,是动态的概念,进程需要占内存空间 线程是进程的基本单位,一个进程至少有一个线程,iOS程序默认有一个主线程,用来显示和操作 ...
- Weblogic 部署注意事项
Weblogic下部署服务注意事项: 1. 解决weblogic与hibernate的jar包冲突问题: 首 先找到该系统的DOMAIN_HOME(即你所建的域所在的位置)如:域empi的DOMAIN ...
- EC读书笔记系列之9:条款16、17
条款16 成对使用new和delete时要采取相同形式 记住: ★若你在new表达式中使用[ ],必须在相应的delete中也使用[ ],反之亦然 -------------------------- ...
- C语言栈的实现
栈是常用的数据结构之一,下面给出一个链式栈的实现~~头文件Stack.h #ifndef Stack_H #define Stack_H typedef int Item; typedef struc ...
- JavaWeb核心编程之(三.5)HTTP请求和接受表单数据
HTTP简介WEB浏览器与WEB拂去其之间的一问一答的交互过程, 必须遵循一定的规则,这个规则就是HTTP协议HTTP是hypertext transfer protocol(超文本传输协议)的简写, ...
- 各种数据库的批量插入操作_Oracle
最近工作中需要优化以前各种的Excel批量导入功能,目前将能优化的方面做个记录. 选用技术: 目前.Net可以访问Oracle常用的Dll,有三种: 微软自带的 System.Data.OracleC ...
- NodeJS + express访问html、css、JS等静态资源文件
原先做前端开发时都是用XAMPP或LAMP,把HTML.CSS.JS等前端资源放到htdocs下,测试自己的前端代码,但有些不方便的地方是,在调用Ajax请求后无法模拟请求返回的数据,最近学了点Nod ...
- javaTemplates-学习笔记四
应用的调用顺序理解 这个地方很薄弱,浏览器 http://localhost:9000/index.html -> conf/routes -> app/controllers/A ...
- 发布MFC ActiveX控件并实现自动更新
一. 引言 上一篇我们讲了如何使用 VC 2005来开发 MFC ActiveX控件,我们开发 ActiveX控件最终目的是将 ActiveX控件发布出来并嵌入在 Web网页中,随着控件 ...
- c# 搭建服务端 常用的Helper(5)
常用的Helper 1.byteHelper :对象与byte[]之间的转换 2.ConvertJson:操作json对象 3.EncodingHelper:对象编码 4.ModelConvertHe ...