bnu27935--I love memorizing words —————— "array emulation"

Source: Internet
Author: User

I love memorizing words time limit:1000msmemory limit:65536kb64-bit integer IO format:%lld Java class name: Main Prev Submit Status Statistics discuss Next

In order to prepare for the GRE exam, big jade son every day to recite the word. New Oriental Teacher said, recite the word is constantly repeating, so he made a plan, the first day after the initial memory, in the next some days (such as the second day, the fourth day, the seventh day, 15th day, 30th Day) and then read the words again. He found that the method worked well, but for a few days a month he needed to see very, very many words. So, he wants to write a program to know how many words a day needs to see.

Big Jade son a total to back d days of new words (ie no review of the case, to continuously back d days), the number of new words on the back of each day is n1,n2,... ND. He also developed a K review point, R1,R2,..., RK, said in the back of the day after the word R1 day, the first R2 days, ..., the first day, he will go over the word that day (all the new word D will follow the plan review). Ri=1, then the word back the same day to review, Ri=2 said the back of the day after the new words will be reviewed again.

Next, the big Jade son will have m inquiry, q1,q2,..., QM, the first I asked the big jade son want to know how many words Qi day will see (including the day to remember the new words).

Input

The test data has multiple groups, the first line is an integer T (0<t<=30), which represents the number of data groups.

For each set of data, the first line is a positive integer d (1<=d<=100), and the next line has a D integer N1 N2 ... ND, separated by a space between each number, Ni represents the number of new words that Big Yu is looking at on the first day (1<=ni<=2000). The third line has a positive integer k (1<=k<=100), which indicates that there are K review points. The four lines have k integers R1 R2 ... RK, which indicates the time of this K review point (Guaranteed R1<r2<...<rk, and 1<=ri<=2000). Line five is a positive integer m, which indicates a M query (1<=m<=10000). Line six has m integers Q1 Q2 ... QM (1<=qi<=10000), said Big Yu want to know the first Qi days to see how many words (from the beginning of the day to recite new words counted as the first day).

Output

For each set of data, for each query output line, line I indicates the number of words Qi Tianda wants to see.

Sample Input
133 5 1032 3 5101 2 3 4 5 6 7 8 9 10
Sample Output
38181513510000

Error point: Test instructions Understanding ability not, have been reading not understand what is the meaning of the RI Review ~o (╯-╰) o
Not zeroing the array, always thinking that the array declared in the while loop will automatically clear the array every time, and it seems to be more ...


The idea of solving problems: simulating the expression process.

#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int main () {    int T;    scanf ("%d", &t);    while (t--) {        int n[110];        int r[110];        int ans[11000];        int D;        memset (ans,0,sizeof (ans));        scanf ("%d", &d);        for (int i=1;i<=d;i++) {            scanf ("%d", &n[i]);            Ans[i]=n[i];        }        int K;        scanf ("%d", &k);        for (int i=1;i<=k;i++) {            scanf ("%d", &r[i]);        }        for (int i=1;i<=d;i++) {for            (int j=1;j<=k;j++) {               ans[i+r[j]-1]+=n[i];            }        }        int M;        scanf ("%d", &m);        for (int i=1;i<=m;i++) {            int tmp;            scanf ("%d", &tmp);            printf ("%d\n", Ans[tmp]);        }    }    return 0;}

  



bnu27935--I love memorizing words —————— "array emulation"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.