2017 Completion Report of Day1 simulated exam, day1 Completion Report

Source: Internet
Author: User

2017 Completion Report of Day1 simulated exam, day1 Completion Report

Expected score: 100 + 50 + 50

Actual score: 5 + 50 + 100

=. =

Multiple backpacks

(Backpack. cpp/c/pas)

(1 s/256 M)

Description

Provide a backpack that can carry up to W items.

Now N items are provided: for category I items, there are a total of Ci items. For each item, the weight is Wi and the value is Vi.

Find a method of loading to maximize the total value of items in the backpack.

Input Format(Backpack. in)

The first two integers N, W represent the type of the item and the total weight of the backpack.

2nd ~ N + 1 rows. Each row has three integers, namely, Wi, Vi, and Ci, representing the weight, value, and quantity of the I-th item.

Output Format(Backpack. out)

Only one row, an integer V, represents the maximum total value.

Sample Input

3 9

5 8 2

3 6 2

2 1 5

Sample output

14

Data scope and restrictions

1 <= N <= 20, 0 <= W <= 1000

1 <= Wi <= 100, 0 <= Vi <= 100, 0 <= Ci <= 100

As soon as I saw this question, I immediately thought of dynamic planning, which was a complete backpack problem, but I had no choice but to learn it because I had never learned it well. Instead, I had to fight the violence silently;

The data range is quite small, and the teacher meant to make us violent ..

After 20 minutes of brute-force attacks, I habitually made several sets of extreme data and changed my mistakes,

But ........

Because the tracing I wrote is special... ,

So ........

You can only use extreme data ....

.......

I was drowned by such water questions ,,,

AC code:

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <stack> 6 # include <queue> 7 # include <algorithm> 8 using namespace std; 9 struct node10 {11 int w; // weight 12 int v; // value 13 int num; // number 14 int gdnum; 15} a [40]; 16 int n, m; 17 int ans = 0; 18 void dfs (int nownum, int nowv, int noww) // current backpack id value weight 19 {20 if (nowv> ans & noww <= m) {ans = nowv;} 21 if (noww> m | nownum> n) return; 22 23 int p = a [nownum]. gdnum; 24 25 for (int I = 0; I <= p; I ++) 26 {27 if (a [nownum]. num> 0) 28 {29 a [nownum]. num = a [nownum]. num-I; 30 dfs (nownum + 1, nowv + a [nownum]. v * I, noww + a [nownum]. w * I); 31 a [nownum]. num = a [nownum]. num + I; 32} 33} 34 35 36 // dfs (nownum + 1, nowv, noww); 37} 38 int main () 39 {40 // freopen ("backpack. in "," r ", stdin); 41 // freopen (" backpack. out "," w ", stdout); 42 43 scanf (" % d ", & n, & m); 44 45 for (int I = 1; I <= n; I ++) 46 {47 scanf ("% d", & a [I]. w, & a [I]. v, & a [I]. num); 48 a [I]. gdnum = a [I]. num; 49} 50 51 52 dfs (1, 0); 53 54 printf ("% d", ans); 55 56 fclose (stdin); 57 fclose (stdout ); 58 return 0; 59}

Cyclic Sequence

(Circulate. cpp/c/pas)

(1 s/256 M)

 

Description

Alice and Bob are playing games:

Alice first gives two numbers X and Y (X <= Y );

Bob converts X, X + 1, X + 2 ,..., Y-1, Y is written as a large number S.

Alice finally connects S at the beginning and end to form a circle.

Bob wants to know, starting from the beginning of SBitTo RBitThe sum of numbers.

Input Format(Circulate. in)

The four integers X, Y, L, and R in the first line represent the sum of Alice's two numbers and the numbers from the nth digit to the nth digit Bob wants to know.

Output Format(Circulate. out)

Only one row, an integer M, represents the sum of numbers from the nth digit to the nth digit.

Sample Input

10 11 4 12

Sample output

7

Example

Bob writes a number into a row with a large number of S = 1011. After a circle is formed, the numbers from 4th to 12th are, and 1. Their sum is 7.

Data scope and restrictions

For 50% of data, L = 1, X, Y, L, R <= 1000;

For 100% of data, the length of S is not greater than 10000, X, Y, L, R <= 100000000.

It was a bit difficult to read questions at the beginning, but it was not difficult to find out after a while, that is, the data processing was complicated.

Then, without saying anything, we start to simulate...

However, only when you read the data range is the data that exceeds 50%.

After thinking for a while, I didn't come up with any good algorithms ....

So I submitted a copy of the simulated brute force code.

Sure enough-> 50 points

Positive Solution:

Because it is very likely that l-r will produce cyclic computation, we can directly find the multiples of l and r for the generated string plus the remainder.

Because it is very complicated to generate every digit of a string in cyclic computing, we can create a prefix and so as to greatly reduce the time complexity.

Timeout code:

TLE

AC code:

1 # include <iostream> 2 # include <cstdio> 3 using namespace std; 4 int x, y, l, r; 5 int a [10001]; 6 int numa = 1; 7 int B [1001]; 8 int numb = 1; 9 int qiu (int o) 10 {11 return o/numa * a [numa] + a [o % numa]; 12} 13 int main () 14 {15 scanf ("% d", & x, & y, & l, & r ); 16 for (int I = x; I <= y; I ++) 17 {18 int p = I; 19 numb = 1; 20 while (p! = 0) 21 {22 B [numb ++] = p % 10; 23 p = p/10; 24} 25 for (int I = numb-1; i> = 1; I --) 26 {27 a [numa ++] = B [I]; 28} 29} 30 numa --; 31 for (int I = 1; I <= numa; I ++) 32 {33 a [I] = a [I-1] + a [I]; 34} 35 cout <qiu (r) -qiu L-1; //-1 is used to specify the number of elements of element l twice 36 return 0; 37}AC

Merge games

Merge. cpp/c/pas

(1 s/256 M)

Description

Cindy and Dan are playing a game.

At first Cindy came up with N numbers, and then she gave all N numbers to Dan.

After Dan gets the number of these groups, it will pick out three numbers (if there are less than three, all of them will be picked out ). Dan adds these numbers into one, and then puts them together with the remaining ones. Dan will keep doing this until there is only one number left.

Cindy writes down the number that Dan gets each time. She adds these numbers as the score of this game. She wants to know what is Dan's maximum score for a group of numbers?

Input Format

The first line is a positive integer N, which represents the number of the groups;

N integers in the second row.

Output Format

A row is an integer that represents the maximum possible score.

Sample Input(Merge. in)

4

3 1 5 6

Sample output(Merge. out)

29

Example

Dan can first combine the three numbers (3, 5, 6) to get 3 + 5 + 6 = 14, and then combine the remaining two numbers, 1 + 14 = 15. in this way, the total score is 14 + 15 = 29.

Data scope and restrictions

For 50% of the data, N <= 10

For 100% of data, N <= 1000, all numbers cannot exceed 1000

When I read the questions, I thought of dynamic planning, heap, greedy, and priority queue ....

But none of them will ,,,,..,,.,.,.,..

So still follow the sensory Simulation

I did not expect that the last AC is =. =

Good dog blood ......

AC code

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <stack> 6 # include <queue> 7 # include <algorithm> 8 using namespace std; 9 int n; 10 int a [10001]; 11 int ans = 0; 12 int flag = 0; 13 int now = 0; 14 int comp (const int &, const int & B) 15 {16 return a> B; 17} 18 void gett () 19 {20 now = 0; 21 if (a [1]! =-1 & a [2] =-1) 22 {23 // ans = ans + a [1]; 24 flag = 1; 25 return; 26} 27 for (int I = 1; I <= 3; I ++) 28 {29 if (a [I] =-1) continue; 30 now = now + a [I]; 31 a [I] =-1; 32} 33 ans = ans + now; 34 a [1] = now; 35 sort (a + 1, a + n + 1, comp); 36} 37 int main () 38 {39 freopen ("merge. in "," r ", stdin); 40 freopen (" merge. out "," w ", stdout); 41 scanf (" % d ", & n); 42 43 for (int I = 1; I <= n; I ++) 44 scanf ("% d", & a [I]); 45 46 sort (a + 1, a + n + 1, comp ); 47 48 while (flag = 0) 49 {50 gett (); 51} 52 53 printf ("% d", ans); 54 fclose (stdin ); 55 fclose (stdout); 56 return 0; 57}AC

 

 

Summary:

In this test, we cannot say that the test is very good, because two of our school's top experts have obtained full marks. This gap is definitely not just half a bit. from ideas to code, from examples to extreme data, they are far above me.

But it cannot be said that the test is very bad. At least no super-low-level errors like the previous three tests have been made (in fact, the first question has also made a low-level mistake =. =), which is also a turning point.

The first question is nothing (indeed not worth it)

Question 2 timeout (too narrow)

Question 3 AC (luck)

At least there is no question about that kind of thinking. It means there is still room for improvement.

Come on!

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.