Google Code Jam 2012 Practice - Store Credit

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

/*
*   author:wxg
*/
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

void solution(){
    int n;
    vector<int> c,l,first,second,max;
    vector<vector<int> > p;
    int i,j;
    cin>>n;
    for(i=0;i<n;i++){
        int ctmp,ltmp;
        vector<int> ptmp;
        cin>>ctmp>>ltmp;
        c.push_back(ctmp);
        l.push_back(ltmp);
        for(j=0;j<ltmp;j++){
            int vtmp;
            cin>>vtmp;
            ptmp.push_back(vtmp);
        }
        p.push_back(ptmp);
    }
    for(i=0;i<n;i++){
        int ctmp=c.at(i);
        int np=l.at(i);
        int max=0,ftmp,stmp;
        for(j=0;j<np;j++){
            for(int k=j+1;k<np;k++){
                int mtmp=p.at(i).at(j)+p.at(i).at(k);
                if(max<mtmp&&mtmp<=ctmp){
                    max=mtmp;
                    ftmp=j;stmp=k;
                }
            }
        }
        first.push_back(ftmp+1);
        second.push_back(stmp+1);
    }

    for(i=0;i<n;i++){
        cout<<"Case #"<<i+1<<": "<<first.at(i)<<" "<<second.at(i)<<endl;
    }

}
int main(){
    freopen("A-large-practice.in","r",stdin); //重定向标准输入和输出流
    freopen("output.txt","w",stdout);
    solution();
    fclose(stdin);
    fclose(stdout);
    return 0;
}

Google Code Jam 2012 Practice - Store Credit

时间: 2024-10-24 21:06:36

Google Code Jam 2012 Practice - Store Credit的相关文章

Google Code Jam 2014 Round2

Google Code Jam Round2 晚上10点开始的,开始google一直上不去,然后开了个vpn就行了. 说说我的情况吧. P1就是某年noip普及组纪念品分组,贪心. p2是说给你一个排列,然后每次可以交换两个相邻的数,使得最后序列变为先上升后下降的样子.(n<=1000) 一开始题目看错了,以为是交换任意两个,然后愣了半天不会,去写后两题暴力了. (话说我Round1Cp1题目也看错了害的我逗了好久) 后来突然发现是adjacent elements...(<论英语学习的重要性

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

Java学习笔记(5)----使用正则表达式解决Google Code Jam Qualification2009赛题 Alien Language

原题地址:https://code.google.com/codejam/contest/90101/dashboard#s=p0 题目描述: Problem After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word

Google Code Jam 2014 Round 2回顾和分析

回顾 比赛开始网络就一直在抽风,不知道宿舍网渣还是有人攻击服务器.刷了n遍n久刷出了题目.提交A小case的时候眼睁睁看着时间过去,却提交不上,这破网.最后A题B题还是解决了,C题扫了一眼,读都没读,就奔D题去了,因为我看到了熟悉的trie这个单词,加之看到小case只有9分,判断小case应该比较容易.前面因为网络浪费了很多时间,加之从未编过trie的程序,只能临时上网翻书去学,最后D小这个可以很容易暴力解的问题也没编完. 最终的rank是13xx,考虑到在这次GCJ之前从未接触过编程竞赛,而

Google Code Jam在线测试题目--Alien Language

Problem After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words

Google Code Jam在线測试题目--Alien Language

Problem After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words

Google Code Jam Round 1A 2015 Problem B. Haircut 二分

Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barbers on duty, and they are numbered 1 through B. It always takes the kth barber exactly Mk minutes to cut a customer's hair, and a barber can only cut

google code jam -- bad horse

二分图解决这个问题的思路 #include <stdio.h> #include <string> #include <iostream> #include <vector> #include <unordered_map> #include <queue> using namespace std; class Node{ public:     string name;     vector<Node*> adj;   

Google Code Jam 2014 Round 1B Problem B

二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; #define MAX_LEN 50 long long A, B, K; int a[MAX_LEN], b[MAX_LEN], k[MAX_LEN]; long long memoize[MAX_LEN]