[C++]Store Credit——Google Code Jam Qualification Round Africa 2010
来源:互联网 发布:第三方辅助软件 编辑:程序博客网 时间:2024/05/21 06:34
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
就是找出和正好等于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
- Store Credit-GOOGLE CODE JAM AFICA 2010 Qualification Round
- Qualification Round Africa 2010 Problem A. Store Credit
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- googlecodejam.Qualification Round Africa 2010.Problem A. Store Credit
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
- [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
- [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
- Google Code Jam 2010 is in Dublin!——Qualification Round
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2015 Qualification Round: Problem C. Dijkstra
- Google code jam: Problem A. Store Credit
- Google Code Jam Notes - Store Credit - Java
- 【Google Code Jam】Problem A. Store Credit
- Reverse-GOOGLE CODE JAM AFICA 2010 Qualification Round
- T9 Spelling-GOOGLE CODE JAM AFICA 2010 Qualification Round
- 2009 Google Code Jam Qualification Round 题解
- Google Code Jam 2011 Qualification Round ProblemA
- matlab工具箱LS-SVMlab的安装
- Spring MVC+MyBatis+MySql 具体实践
- 【HTML】Canvas(2)-绘制文本
- C语言中数组名并非数组首地址
- thinkphp 页面跳转传递参数
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
- cygwin 恢复快捷方式。
- 用于私网的IP地址段
- LUG 每周小聚(可以看看)
- 网址汇总
- Qt Quick里的图形效果:阴影(Drop Shadow)
- IOS中键盘隐藏方法总结
- Cocos错误集锦
- 大型网站系统架构的演化