Several solutions to a contest

Source: Internet
Author: User

[Preface]

On Saturday, I ran to the lab for review.

Half of the review shows a contest. After reading a question, I thought I could do it, and then I got yy.

And then it's out of control ......

I did not do ACM for a long time and have been busy with big jobs recently.

[Question]

First, you can see the third question. Because those questions are not available for HDU, you can only copy them.

Since each number is small, you can just open an array and save it.

So I knocked out the question. It seems that the title of "water question Emperor" is indeed worthy of the name.

Xiaoqiang and her story time limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 16 accepted submission (s ): 9 Font: Times New Roman | verdana | georgiafont size: encounter → problem descriptionustc the annual "beautiful encounter" is very popular, especially the "Millennium Singles Day", which is a rare millennium this year ", of course, in this activity, the legendary Xiaoqiang must join in the crowd. "looking for him in the crowd, then looking back, the man is in the dark." Xiaoqiang finally met the legendary one, as a result, she picked up the conversation, but she recognized Xiaoqiang at a glance before Xiaoqiang was able to speak. (It may be because she was too handsome ). So she turned out to be a cool man. "little brother, it's hard to find you. Our algorithm teacher gave me a question. No, I asked many people, none of them. If Mr. Xiaoqiang's brother does... Me ...". When Mr. Xiaoqiang heard these things, he suddenly burst into a ripple, but he pretended to be calm, and man said, "Say !". So she said the problem that had plagued her for a long time.
There are n positive integers to find the sum of the absolute values of their two differences. For example, there are four numbers:
4 3 5 2, then the answer is:
| 4-3 | + | 4-5 | + | 4-2 | + | 3-5 | + | 3-2 | + | 5-2 | = 10
This is simply a piece of cake for Xiaoqiang ". However, Xiaoqiang has other sisters who want to encounter this problem, so I will leave it to you. The first line of input is a positive integer T (t <= 100), which indicates that there are T groups of test data. Each group of test data includes two parts:
First, a positive integer N (1 <=n <= 100000) represents n integers.
Next, enter n positive integers, each of which must not be greater than 200. Output outputs the corresponding answer. The answer may be out of the int range, but cannot exceed the long range. Sample Input
144 3 5 2
Sample output
10
Authorgamegame151

[Code 1003]

#include <iostream>using namespace std;#define LL __int64int num[205];int main(){int t;int n, x, i, j;LL sum;scanf("%d", &t);while(t--){scanf("%d", &n);memset(num, 0, sizeof(num));sum = 0;for (i=0; i<n; i++){scanf("%d", &x);num[x]++;}for (i=1; i<=200; i++){if (num[i]!=0){for (j=i+1; j<=200; j++){if (num[j]!=0){sum += (LL)(j-i)*num[i]*num[j];}}}}printf("%I64d\n", sum);}return 0;}

Then we found that 1007 is a + B. Ah, copy the Code directly.

Then we can see the second question.

Generate functions and so on. I am not very good at myself, so I still cannot apply it.

So you can just think about it. Because it is an equal sign. So enumeration 5z, for the n-5z to calculate the number of 2y, the rest is X.

The complexity of O (n) can be solved. Later, we found that we could use production functions. The idea was similar, but it may seem more rigorous.

Time Limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 3 accepted submission (s ): 2 Font: Times New Roman | verdana | georgiafont size: Drawing → problem descriptionw recently studied an equation x + 2y + 5z = n, where x, y, and z are unknown, N is a known integer and all X, Y, Z, and n are non-negative integers. He wants to find out how many groups of solutions the equation has. Can you help him? The first line of input is a positive integer T (t <= 100), which indicates that there are T groups of test data. In the following T rows, each row has an integer N (0 <=n <= 1000000 ). Output outputs the number of groups for this equation. Sample Input
206
Sample output
15
Authorgamegame151

[Code 1002]

#include <iostream>using namespace std;int main(){int i;int n, t;__int64 ct;scanf("%d", &t);while(t--){scanf("%d", &n);ct = 0;for (i=0; i*5<=n; i++){ct += (__int64)(n-i*5)/2+1;}printf("%I64d\n", ct);}return 0;}

Then I plan to continue my review. But I couldn't stand the temptation of ACM, so I came back to do it again.

This problem can be solved within 2 ^ 20 because the given number range is relatively small. Therefore, you can create a table first.

Unusual binary time limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 6 accepted submission (s): 3 Font: times New Roman | verdana | georgiafont size, three more. The first is the WA god known as the WA God. Wa God is a famous mathematical emperor and gave lmm a calculus exercise set, "Oh, my God ", lmm, who hates calculus, has the chance to give him ym. The second is the cbx, known as the physical emperor. He also had the opportunity to get ym, because he actually sent a comprehensive reference book of quantum mechanics + quantum chemistry to lmm, lmm hates those things.
The third is known as the WSN (WO Shen NIU). Although he is named WS, he can get the chance to get a close ym lmm. Why? It's easy, because he is a programmer ". ^-^
He knows that lmm is specialized in Cs and is very familiar with binary conversion. For example, the binary value of 13 is 1101, 13 = 1*2 ^ 3 + 1*2 ^ 2 + 0*2 ^ 1 + 1*2 ^ 0, he wants to prove his charm, this brings about the so-called "negative binary" problem. Changing the base number to-2, for example, 1101 actually represents: 1 * (-2) ^ 3 + 1 * (-2) ^ 2 + 0 * (-2) ^ 2 + 1 * (-2) ^ 0 =-3, so the "negative binary" of-3 is 1101.
Do you have this problem as a programmer? If you will, you may still be able to get the chance of ym lmm.
It is harder to get ym to a sister-in-law paper than final... Input Multiple groups of test data, each group input a number N (-100000 <= n <= 100000), representing the number to be converted. Output outputs the corresponding conversion results. Sample Input
-311
Sample output
1101 11111
Authorgamegame151

[Code 1004]

#include <iostream>using namespace std;const int maxn = 100000;struct node{int len;bool by[30];}num[2*maxn+5];int value[30];void dfs(int v, int m, node now, int cur){if (v==m){if (cur<=maxn && cur>=-maxn && num[cur+maxn].len==0)memcpy(&num[cur+maxn], &now, sizeof(node));return;}now.len++;now.by[now.len-1] = false;dfs(v+1, m, now, cur);now.by[now.len-1] = true;cur += value[v];dfs(v+1, m, now, cur);}void show(int n){n += maxn;int i;for (i=num[n].len-1; i>=0; i--){if (num[n].by[i]) break;}if (i<0) i=0;for ( ; i>=0; i--){if (num[n].by[i]) printf("1");else printf("0");}printf("\n");}int main(){int i;value[0] = 1;for (i=1; i<20; i++) value[i] = value[i-1]*(-2);for (i=-maxn; i<=maxn; i++) num[i+maxn].len = 0;node now;now.len = 0;dfs(0, 20, now, 0);int n;while(scanf("%d", &n)!=EOF){show(n);}return 0;}

Seeing that 1008 people quickly came out, it was determined to be a regular question. Start to find the rule.

Then I found it. A drop.

Triangle time limit: 2000/1000 ms (Java/other) memory limit: 65536/32768 K (Java/other) total submission (s): 6 accepted submission (s): 3 Font: times New Roman | verdana | georgiafont size: Drawing → Problem description how many areas can a plane be divided into by N triangles at most? The first line of input data is a positive integer T (1 <= T <= 10000), indicating the number of test data. then there is the T group of test data, each group of test data contains only one positive integer N (1 <= n <= 10000 ). output for each group of test data, please output the results required in the question. sample Input
212
Sample output
28
Authorignatius. L

[Code 1008]

#include <iostream>using namespace std;const int maxn = 10000;int x[maxn+5];int main(){int i;x[1] = 2;for (i=2; i<=maxn; i++) x[i] = x[i-1] + 6*(i-1);int t, n;scanf("%d", &t);while(t--){scanf("%d", &n);printf("%d\n", x[n]);}return 0;}

Then I decided to start watching 1009 of the time-honored results.

It's just a simple dictionary tree.

I did not expect to be knocked out in 8 minutes. It seems to be a little powerful.

Statistical difficulties time limit: 4000/2000 ms (Java/other) memory limit: 131070/65535 K (Java/other) total submission (s): 3 accepted submission (s): 2 Font: times New Roman | verdana | georgiafont size: Regular → problem descriptionignatius has encountered a problem recently. The teacher gave him many words (only lowercase letters are used and no duplicate words appear ), the teacher asks him to calculate the number of words prefixed with a certain string (the word itself is also its own prefix ). the first part of input data is a word table. Each line has one word. The length of a word cannot exceed 10. These words represent words that the teacher gave to Ignatius for statistics. A blank line indicates the end of the word table. the second part is a series of questions. Each question in each row is a string.

Note: This question only contains a set of test data. After processing the data to the end of the file, output provides the number of words prefixed with this string for each question. sample input

bananabandbeeabsoluteacmbabbandabc
Sample output
2310
Authorignatius. L

[Code 1009]

#include <iostream>using namespace std;struct node{int ct;int next[26];}tree[400000];int tct;int root;int new_node(){memset(&tree[tct], 0, sizeof(node));return tct++;}void insert(char *s){int rt = root;int i = 0;while(s[i]!='\0'){tree[rt].ct++;int tmp = s[i]-'a';if (tree[rt].next[tmp]==0)tree[rt].next[tmp] = new_node();rt = tree[rt].next[tmp];i++;}tree[rt].ct++;}int solve(char *s){int rt = root;int i = 0;while(s[i]!='\0'){int tmp = s[i]-'a';if (tree[rt].next[tmp]==0) return 0;rt = tree[rt].next[tmp];i++;}return tree[rt].ct;}int main(){char str[20];tct = 0;root = new_node();while(gets(str)){if (str[0]=='\0') break;insert(str);}while(gets(str)){printf("%d\n", solve(str));}return 0;}

The last three questions are not answered.

The first question seems to be a line segment tree. I saw it a while ago, but I haven't learned it yet.

Sequential operation time limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 0 accepted submission (s): 0 Font: times New Roman | verdana | georgiafont size: Regular → Problem description gives you a sequence composed of n positive integers. Now you can perform the following two operations on the sequence:
Q l r: the length of the Subsequence in the output range [L, R] (1 <= L, r <= N) is the longest consecutive and does not decrease.
C l r p: replace each integer in the range [L, R] (1 <= L, r <= n) with an integer p.
As USTC's program elites, can you solve this problem smoothly? The first line of input is a positive integer T, which indicates that there are T groups of test data (T <= 10 ).
For each group of test data:
First, enter two positive integers, n q (1 <=n <= 100000,1 <= q <= 100000), representing the sequence length and number of operations, respectively.
Then, enter n positive integers (each positive integer must not be greater than 1000 ).
The last input of the Q row indicates that there are Q operations. Each row has two possible forms: q l r or
C l r p. Meaning as shown above, where p is not greater than 1000.
Note: l may be greater than R. For each q l r operation, output ranges [L, R] have the longest continuous length of the subsequence without descent. Sample Input
16 51 2 3 4 5 6 Q 1 6         C 4 3 2Q 1 3C 4 5 3Q 2 5
Sample output
634
Authorgamegame151 the fifth line seems to be able to be done in binary mode, but at that time there was no time. K_star storm time limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 0 accepted submission (s): 0 Font: times New Roman | verdana | georgiafont size: Regular → problem descriptionustc's k_star has become one of USTC's symbolic cultures. Every year, many handsome men and girls will be invited to the competition. Of course, this year is no exception. Now assume there are n singers and M judges. The artist number is 1, 2 ..., N, judges 1, 2 .. M. The time for singer singing is T1, T2,..., TN. Judges need to comment on singers, and each singer needs and only one judge. Each judge must comment on at least one singer, in addition, each judge can only comment on some consecutive singers. The comment time is the sum of the singing time of these singers.
Now, please design a comment scheme so that the comments can spend as short as possible. The comment time of the judges is defined as the time spent by the judges who have the most comments.
For example, suppose there are five singers and three judges. The singer's singing time is 4 5 3 1 2 in sequence, so you can make a comment like this: 4/5 3 1/2, that is, the first judge commented on the first singer, with four units used; the second judge commented on the second, third, and fourth singers in 9 units; the third judge commented on the fifth singer in 2 units; then the comment time for this solution was 9.
Of course, this is not the optimal solution. You need to use a program to find the optimal solution. The first line of input is an integer T (t <= 100), representing a total of T groups of test data.
Each group of test data includes two parts:
Part 1: n m represents the number of singers and judges respectively. (1 <= m <= n <= 500)
Part 2: n positive integers, representing the singing time of the singer (positive integers not greater than 2000 ). Output includes m + 1 rows. The first row has the shortest comment time. Line I (2 <= I <= m + 1) is the start number and end number of the singer to be commented on by the judges of the I-1, if there are multiple groups of solutions, minimize comments from previous judges. Sample Input
15 34 5 3 1 2
Sample output
61 12 23 5
Authorgamegame151

Sixth is the problem of the largest submatrix. But I have not thought about it. RG story time limit: 3000/1000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 2 accepted submission (s): 0 Font: times New Roman | verdana | georgiafont size: Drawing → Problem description I believe everyone has done the legendary "to the max" question, which is roughly described as follows:
This is a matrix of N * m numbers. It contains several submatrices that define the sum of submatrices and all numbers in the submatrix, we can compare all child matrices to find out the sum of the largest child matrices.
For example, the following matrix is used:
0-2-7 0
9 2-6 2
-4 1-4 1
-1 8 0-2
The maximum submatrix is 15, and the corresponding submatrix is:
9 2
-4 1
-1 8
I believe everyone can quickly solve this problem. In fact, you can also find the number of sub-matrices that satisfy the sub-matrix and the maximum (in the above example, only one sub-matrix is 15 and the maximum ).
Sorry, I believe it's hard for you !!! Input a number T (t <= 20) in the first line, which indicates that there will be T groups of test data. Each group of test data includes two parts:
Part 1: two positive integers n, m (0 <n, m <= 100), respectively, the dimension of the matrix.
Part 2: An N * m numeric matrix in which the range of each number is [-1000,100 0]. For each group of test data, output outputs the maximum child matrix and the maximum number of child matrices. Separated by spaces. Sample Input

12 30 0 00 0 0 
Sample output
0 18
Authorgamegame151

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.