Sharing of simulated exam topics

Source: Internet
Author: User

1. Domino (Domino.pas)

JZABC has a lot of interest in dominoes, but his dominoes are special, with only two black and white ones. He felt that if there were three consecutive dominoes of the same color, then the domino arrangement would not be beautiful. Now he has n dominoes to arrange, and he wants to know the number of unsightly permutations. Because of the large number, the math is not good he does not count, so he asked you to help. I hope you find the number of unsightly permutations in one second.

" input "

There is only one positive integer, which is the number of dominoes to arrange.

" Output "

A number, that is, an unsightly number of permutations.

" Sample Input "

4

" Sample Output "

6

" Sample Interpretation "

There are four kinds of unsightly permutations.

Black black Black, white, black black and white, white and black in vain, black black

" Data range "

20% of data, n≤60;

50% of data, n≤600;

100% of data, n≤20000

2. overtaking (Overtaking.pas)

In addition to the domino interest, JZABC is also interested in racing cars. He watched a racing game last weekend. He can always come up with many strange problems. At one point, he saw N cars (always traveling at a constant speed) in the same straight line, and on an infinite length of straights, and N cars have a strict succession of points. He measured the speed of each car through special equipment. Then the problem arises, if there are two cars A and B cars, a car behind the B car, and a car faster than the B car, then after a period of time, a car will be more than B car. We call it a overtaking. Then he would ask you to help calculate the total number of overtaking. We remember that the coordinates of the beginning of the driveway are 0. No two cars have the same coordinates.

" input "

The first line, a number n, the total number of vehicles. The following n acts n two vehicles of information;

The second line to line n+1, there is a space between two positive integers x,y,x and y per line. X is the coordinates of the car, and y is the speed of the car.

0<x,y≤1000000000

" Output "

Line, the total number of overtaking.

"Sample Input"

2

5 6

2 8

" Sample Output "

1

"Data Range"

20% of data, n≤300;

50% of data, n≤3000;

100% of data, n≤300000

3. Minimum Reward (Minaw.pas)

JZABC is also an avid travel enthusiast. This time he wanted to go to a strange place. This place has n villages, numbered 1 to N. At the moment he was in village 1th, and he wanted to go to the village of N, which had M-one-way roads between the N villages. When you pass a road, you may spend some money as a "buy the road", but through some roads, not only do you not have to pay "buy road money", but also get some reward (this is the strange place?). )。 Of course, there may be several directly connected roads between the two villages. But each path can only be passed once. These villages have such characteristics that starting from any village, walking along either path will not return to the starting point. After finding a route from village 1th to village N, he needed to calculate how many prizes he had received, and how many "buy road money" they had paid. If the total reward amount is greater than the number of "Buy road Money", then the route can be rewarded; Conversely, if the former is less than the latter, then it is necessary to call this path a cost. If the two are equal, then JZABC will not choose this route (I don't know why he chose this path). All paths do not appear equal. He needs your help to find a way to minimize his reward (why not the biggest reward?). ) and output the minimum reward. If you can't find a path that will reward him, find a path that will cost him the most (why not the minimum cost?). ) and output the maximum cost.

" input "

The first line is two positive integer n,m, separated by a space in the middle. n is the total number of villages, and M is the total number of roads.

The following m lines, each line of three positive integers x,y,w, describe the information of a road, separated by a space. X is the starting point for this road, and Y is the end point. If W is positive, it is the amount of prize money obtained through this road, and if W is negative, it is the number of "buy Road" through this road; W is not 0 and |w|≤10.

" Output "

An integer. If there is a minimum reward, the output. Otherwise the output is the maximum cost.

"Sample input 1 "

3 4

1 2 2

2 3-1

2 3 3

1 3-1

" Sample output 1"

1

" Sample input 2"

3 4

1 2 2

2 3-3

2 3-5

1 3-2

" Sample Output 2"

3

" Data range "

20% of data, n≤20;m≤200;

50% of data, n≤50;m≤2000;

100% of data, n≤100;m≤20000

Today, the boring Usaco is suspended, but a mock exam is needed.

Overall, the topic is not very difficult, but the author for various reasons, the test is not good.

Not much to say,

T1:

Requires three connected, just upside down to think, altogether (1<<n) kind of situation, and a link, is the situation of n-1, the same, two is n-2 species (do not understand can self-management)

So the method is very simple, but n=20000, a look, it was frightened, but also to write high precision ...

So happy to write, after writing found will tle!!! So decisive billion + reduce the array.

T1

T2:

At first glance, this is not reverse order, right? Yes, that is!!!

But one thing to note is that speed is equal (the author is wrong for 20 minutes!) )

For inverse pairs, you can use a merge sort and a tree array, and you can refer to the code (merge sort)

T2

T3:

This is a difficult topic (the author muttered), but of course it is a second kill for the great God.

Perform a topological sort directly, then process the maximum reward for each point to N, then judge the 1 to N route.

#include <ctime>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespacestd;intN,m;vector<int> f[ the],w[ the];inttx[ the],deg[ the],s[ the],stop;intdist[ the],h[ the];intmaxct[ the],minaw[ the];voidTopu () {inti,j;  for(i=1; i<=n;++i) {if(deg[i]==0) {Stop++; S[stop]=i; }    }    into=0;  while(stop>0) {i=S[stop]; Stop--; o++; Tx[o]=i;  for(j=0; J<f[i].size (); + +j) {Deg[f[i][j]]--; if(deg[f[i][j]]==0) {Stop++; S[stop]=F[i][j]; }        }    }}intMain () {Freopen ("minaw.in","R", stdin); Freopen ("Minaw.out","W", stdout); inti,j; memset (Minaw,0x7f,sizeof(Minaw)); memset (Maxct,0x7f,sizeof(MAXCT)); scanf ("%d%d",&n,&m); intA,b,c;  for(i=1; i<=m;++i) {scanf ("%d%d%d",&a,&b,&c);        F[a].push_back (b);        W[a].push_back (c); DEG[B]++;    } topu ();  for(i=1; i<=n;++i) {intz=Tx[i];  for(j=0; J<f[z].size (); + +j) {intto=F[z][j]; Dist[to]=max (dist[to],dist[z]+W[z][j]); }    }     for(i=1; i<=n;++i) h[i]=dist[n]-Dist[i]; minaw[1]=maxct[1]=0;  for(i=1; i<=n;++i) {intz=Tx[i];  for(j=0; J<f[z].size (); + +j) {intto=F[z][j]; if(minaw[z]+w[z][j]>0) Minaw[to]=min (minaw[to],minaw[z]+W[z][j]); if(minaw[z]+w[z][j]+h[to]>0) Minaw[to]=min (minaw[to],minaw[z]+W[z][j]); Maxct[to]=min (maxct[to],maxct[z]+W[z][j]); }    }    if(minaw[n]<2000000000) cout<<Minaw[n]; Elsecout<<-Maxct[n]; cout<<"\ n"; return 0;}
T3

Sharing of simulated exam topics

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.