Source: Internet
Author: User

Tags: import 2018 initial interval number knapsack problem length Beijing []

Directory

- Beijing University October 2018 Program Design Competition part of the puzzle (A,C,E,H)
- Events related to competitions
- Contest Links
- Contest topics
- Summarize

- Events related to competitions

Although I guess it was better when I sent this essay, I still put the link up.

A game

I made the title of the contest C. Zzh topic description of water problem`http://116.196.97.99/contest.php如果链接没设置好的话，可以在这里复制网址`

Zzh is the new generation of the northern ACM community, and every day with countless big guys from all over the world to communicate. However, Zzh has limited time for daily water groups. Zzh wants to communicate with as many big-brother as possible. He expressed the strength of each big man with a number ω, and each day with the highest sum of Omega of the big guys to communicate. But Zzh is busy with the water group, so he gave you the problem. After the event, Zzh will give you 2147483647%1 gold as a reward.

InputSingle set of data

The first line of two integers n,m, representing the time of today's Zzh Water group (in minutes) and the number of big guys who want to communicate with Zzh today (<=2000).

After M line, there are two numbers, which represent the time spent (<n) and the Big Guy's Omega (<1000).

OutputToday the sum of the values of the Omega of the big guy who communicates with Zzh.

Sample inputSample output`70 371 10069 31 2`

`5`

This question is a very common knapsack problem, then I will not do, I used their previous code, I review, I reflect!

`#include <iostream>#include <cstring>using namespace std;int main(){ int V,n; cin>>V>>n; int v[2100],p[2100],dp[2100]; memset(v,0,sizeof(v)); memset(p,0,sizeof(p)); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) cin>>v[i]>>p[i]; for(int i=1;i<=n;i++) for(int j=V;j>=v[i];j--) dp[j]=max(dp[j-v[i]]+p[i],dp[j]); cout<<dp[V];}`

Knapsack problem will be, will not write, probably. There's nothing to say, next.

A. Intellectual Grand Prix title description InputOnly one row, with an integer N, representing the number of layers of the large triangle (n<=45000)

OutputThere are two lines,

The first line has only one number, which indicates the number of small triangles;

The second line also has only one number, which indicates the number of energy bars.

Sample output`8`

`64108`

Listen to the opposite of me said a very good to do, but the data is too big.

Emmmmm, OK, no problem, BigInteger go!

Probably the idea is the 1th row 1 triangle, 2nd row 2+1, 3rd line 3+2 ...

Then the energy bar is the 1th row 3, the 2nd row 6, the 3rd line 9 root ...

Very simple one problem, the difficulty is in the data is too big, but, I BigInteger feared who??

` Import java.math.bigdecimal;import Java.util.scanner;import Java.math.biginteger;public class Main {public stat IC void Main (string[] args) {//TODO auto-generated method stub Scanner in = new Scanner (system.in); int N=in.nextint (); BigInteger x1 = Biginteger.zero; BigInteger x2 = Biginteger.zero; BigInteger x3 = Biginteger.zero; BigInteger y1 = Biginteger.zero; BigInteger A1 = Biginteger.one; BigInteger B1 = Biginteger.one; BigInteger A2 = Biginteger.zero; B1=b1.add (A1); B1=b1.add (A1); for (int i=0;i<n;i++) {x1=x1.add (A1); X2=x2.add (A2); A1=a1.add (Biginteger.one); A2=a2.add (Biginteger.one); Y1=y1.add (B1); B1=b1.add (Biginteger.one); B1=b1.add (Biginteger.one); B1=b1.add (Biginteger.one); } x3=x1.add (x2); SYSTEM.OUT.PRINTLN (x3); System.out.println (y1); }}`

Ability to switch between C + + and Java I'm awesome 233333

Next, H, it feels pretty simple.

H. Description of the series of questionsThe story is not made up, M brother!

Given an n-length sequence A, there are now three operations:

1, 1 p x: Change a[p] to X

2, 2 L R: a[l] to a[r] The difference between the maximum value and the minimum value

3, 3 L R: a[l] to A[r] and

Now give you some operation, please find the corresponding value.

The first line enters a number T to represent the number of data groups (1<=T<=10)

Next T Group data, the first behavior of each group of data two integers n, m (1<=n,m<=1e5), respectively, represents the length of a and operands, the next row n integer represents a[1] to an, followed by M line, each line of the input format as given in the operation of the

(1<=p,l,r<=n,0<=x<=1000)

For each set of data

For each operation 2 or 3, output an integer representing the result

Sample output`24 41 2 3 42 1 21 2 72 1 23 1 45 42 7 6 3 82 1 31 3 12 1 53 3 3`

`1615571`

It's really simple, isn't it just some array manipulation? How to do so few people ...

The only thing to be aware of is that the array in question starts at 1.

` #include <iostream>using namespace Std;int suan (int a[],int l,int r) {int m1,m2; M1=A[L]; M2=A[L]; for (int i=l+1;i<=r;i++) {m1=m1>a[i]?m1:a[i]; m2=m2<a[i]?m2:a[i]; } return m1-m2;} int add (int a[],int l,int r) {int s=0; for (int i=l;i<=r;i++) {s+=a[i]; } return s;} int main () {int t,n,m,x,p,y,l,r; cin>>t; while (t--) {cin>>n>>m; int a[n+1]; for (int i=1;i<=n;i++) {cin>>a[i]; } while (m--) {cin>>x; Switch (x) {case 1:cin>>p>>y; A[p]=y; Break Case 2:cin>>l>>r; Cout<<suan (a,l,r) <<endl; Break Case 3:cin>>l>>r; Cout<<add (a,l,r) <<endl; Break } } }}`

Please do not care about my random function name!

And then this time I found my platoon 12??! Never so high, confidence is greatly increased!!!

Come on!

See E seems to do a lot of people, I also try it!

E. Cloud computing Topic descriptionThe ACM society has n cloud servers, each server has a lifetime, and the first server can also use RI days. There are now m tasks that need to be deployed to a cloud server to run, and the J task needs to run TJ days. The J task can be deployed on the I server when and only if Tj <=ri, and each server can only run a single task for the duration of its lifetime. Even if TK+TJ <=ri, you will not be able to deploy the K and J tasks together to the first server, otherwise this problem will lose its role in the check-in question **(I laughed when I saw the characters of the sign-in question)**. In order to take full advantage of the cloud server, you now need to calculate how many tasks can be deployed. And you as a north of the hope of ACM, this problem needs to be solved by you.

Single set of data

The first row of two integers represents N and M

The second row n integers represent r1,r2,...,rn

The third row of M integers represents T1,T2,...,TM

1<= N,M,TJ, Ri <=100000

Output An integer representing the maximum number of tasks that can be deployed to the cloud server

Sample inputSample output

`3`

Since it is a check-in question, haha, then there is nothing to say, come on, I am not afraid of you!

`#include <iostream>#include <algorithm>using namespace std;int main(){ int n,m,s=0; cin>>n>>m; int a[n],b[m]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<m;i++){ cin>>b[i]; } sort(a,a+n); sort(b,b+n); int j=0; for(int i=0;i<m;){ if(b[i]<=a[j]){ i++; j++; s++; } else{ j++; } if(j==n){ break; } } cout<<s;}`

Well, it's easy, just sort it out, and then judge if it's enough.

And then!!! 8th!!!

But unfortunately, I stopped 4, and then did not make out, the rankings also dropped to more than 50, but also very strong Ah! Long time not to do the problem unexpectedly can also break through the last results.

I didn't make it. B. Description of number of primes InputA total of two lines:

The first Action n L, the middle is separated by a space. (1<=n<=100, 1<=l<=7)

The second behavior is a number of n 0~9, separated by a space in the middle.

Only one row, with all the prime numbers that satisfy the condition, is separated by commas, guaranteeing that there is at least a prime number.

Sample inputSample output`10 38 9 1 0 2 3 5 4 7 6`

`547`

I feel the code is no problem, but just can't live. I won't let it go.

D. Description of the building block titleI'm tired of making up stories, M-brother!

There are n blocks, the height of the first building blocks is a[i], and there are several blocks in front of each block that are shorter than it.

Multiple sets of inputs, each set consists of two lines, the first line of N, the second line of n number, the height of n bricks a[i]

(1<=n<=100000) (1<=a[i]<=1000000000)

Each set of data output n number, number I is the number of bricks in front of the first building blocks than he

Sample inputSample output`51 2 3 4 5`

`0 1 2 3 4`

This problem is loved by the timeout, and finally did not find a good algorithm.

Don't understand, don't want to see F Luo Dalao's password title descriptionAs we all know, Luo Dalao is very powerful. One day, Luo Dalao invented a password to encrypt the document (it can be thought that the document is a string s of length n).

Luo Dalao to s[l]...s[r] encryption, first to reverse the interval s[l]...sr, then k= (r-l+1)/2 (rounding down), and then reverse the interval s[l]...s[l+k-1] and s[l+k]...s[r], and so on, Until the interval length is 1. (Encrypt entire document equivalent to encryption interval s[1]...s[n])

One day you found a Dalao encrypted document, and now you want to find the location before the character is encrypted.

The first line inputs the integer t (0<t<=1000), which represents the number of data groups, the next T line, two integers per line n and P (1<=p<=n<=1e18), respectively, indicating the document length and the location of the query.

OutputOutput t lines, one integer per line, representing the original position of the characters at p position in each set of data

Sample inputSample output`44 14 24 34 4`

G. Luo Dalao's small film title description`3412`

Luo Dalao is very strong, so there will be a lot of people ask him some questions, and he has l minutes a day dedicated to answering questions. Because there are a lot of people to consult, so to find Luo Dalao ask questions, need to book.

So, Luo Dalao know that every day there will be N people to ask questions, the first arrival of the person in the first AI minutes to arrive, Luo Dalao answer questions to use Ti minutes (Luo dalao astute arrangements to ensure ai+ti<=ti+1 and an+tn<=l), However, Luo Dalao want to find free time to watch a small film, Luo Dalao see every small film to see the tail, period can not be interrupted, each small film of the time is M, Luo Dalao want to know how much he can see at most of the small film, now please help him calculate.

Single Group

First row 3 integers: n,l and M (0<=n<=1e5,1<=l<=1e9,1<=m<=l)

Next n lines, two integers per line ai and Ti (0<=ai<=l-1,1<=ti<=l)

Output An integer that shows how many small movies Dalao can see

Sample inputSample output`2 11 30 11 1`

I.leo's Simple Law problem description`3`

Leo likes to eat barbecue, and only eat three kinds, mutton kebabs, vegetables, ham sausage, she ate barbecue before like to put a long string of barbecue, and there are special placing rules, wrong she this meal will not eat.

The rules are: 1. For a continuous three grilled skewers, no three skewers are the same.

2. For the continuous three grilled skewers, if there are three kinds of grilled skewers, green vegetables can not be placed in the middle (eat meat midway between eating is very self-closing)

3. is still for the continuous three grilled skewers, the first and third strings are vegetables, the middle can not be mutton or ham sausage (she meant to diet to lose weight)

Now there are three kinds of grilled skewers have countless roots, she would like to put a grilled string of length n, please find out the number of programs (because the results may be very large, so just give answer modulo 1000000007)

The first line has a number T (t<100), which indicates that there is a T group of data

Next T line, one number per line N (1≤n≤1010)

For each set of data, the output is assumed to be the number of packages with a length of n baked skewers

Sample inputSample output`42346`

Problem J.leo Simple Series Topic description`92046244`

Leo has two numbers, and their lengths are N.

At the very beginning, the a sequence is the 0,b sequence is the number of n randomly populated by Leo (the number is 1-n, to ensure that the B-series is an arrangement of 1-n)

Now Leo can do both of these things.

\1. Add L R means she gives a sequence from a[l],a[l+1],..., A[r], plus a

- Query L R indicates that she wants to know the sum of all items when l<= i <=r a[i]/b[i] (rounded down)

Of course, Leo in mathematics this piece is not very skilled, last monthly exam mathematics only 110 points, so I would like to ask you to help her complete these operations

Multiple sets of data

For each set of data, the first row has 2 digit n,q, which represents the length and operand of a and B. 1<= N,q < =100000

The second line has n digits, indicating the initial state of the sequence B

Next Q line, one operation per line, specific operation format as given in the topic

1<= L <= R <= N

For each query operation, the output line represents the result of the summation.

Sample inputSample output`6 106 1 4 3 2 5query 1 4add 2 2query 3 6add 1 6add 3 4query 2 5query 1 6add 2 4query 1 4query 3 5`

Summarize`002241`

I really can only do a simple question.

Competition website

Beijing University October 2018 Program Design Competition part of the puzzle (A,C,E,H)

Related Article