NetEase 2019 School Recruit C + + research and development engineer written test programming problem

Source: Internet
Author: User

Title Description: Again to the harvest season, coincides with the small easy to go to cattle and cows in the orchard to play. New often said he knew every place in the orchard, small easy to believe, so he wanted to test cattle and cattle. There are n stacks of apples in the orchard, and the number of apples per heap is AI, and it is easy to know which stacks of x apples are left to right. Niuniu thought this was a big problem, so I hope you did, he answered. Input Description: First row one number n (1<=n<=100000) the second row n number of AI (1<=ai<=1000), which represents the number of apples from left to right, the third row of the heap has a number m (1<=m<=100000), indicating that there is an M-polling port. The number of M in the four-row means small easy to know which pile of Qi Apple belongs to. Test examples:

5
2 7 3) 4 9
3
1 25 11

Output

1

5

3

Ideas:

Prefixes and + two points

The I position indicates the total number of apples in the front I heap, using binary search to enter the location of the Apple

Code:
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<queue>#include<map>#include<list>#include<utility>#include<Set>#include<algorithm>#include<deque>#include<vector>#defineIO Ios::sync_with_stdio (false); \Cin.tie (0); Cout.tie (0);using namespaceStd;typedefLong Longll;typedef Vector<int>VI;Constll INF =0x3f3f3f3f;Const intMoD = 1e9 +7;Const intMAX =100000+5;intA[max];intFront_a[max];intMain () {intn,m; scanf ("%d",&N);  for(inti =1; I <= N; i++) {scanf ("%d", A +i); Front_a[i]= front_a[i-1] +A[i]; } scanf ("%d",&m);  while(m--) {        intQ; scanf ("%d",&q); intleft =1, right =N;  while(Left <Right ) {            intMiddle = (left+right)/2; if(Front_a[middle] <q) { left= Middle+1; }            Else if(front_a[middle]>q) { Right=Middle; }Else{ Left=Middle;  Break; }} printf ("%d\n", left); }    return 0;}/*7 3 4 931*/

NetEase 2019 School Recruit C + + research and development engineer written test programming problem

Related Article

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.