Click farming question (1)

Source: Internet
Author: User

Well, I saw a lot of questions from yyl recently (as is LZW), so I opened their record and clicked on the questions they have painted (this sentence seems familiar to me ?)I have never heard of such a watery question !!!And then, with this article.

Question 1: sum of the maximum continuous subsequences

I am very happy to think about it.

#include <cstdio>int f,i,j,n,m,p;int main(){  m=1<<31;  scanf("%d",&n);  for(i=0;i<n;++i){    scanf("%d",&j);    if(f<0){      p=0;      f=0;    }    ++p;    f+=j;    if(p&&f>m) m=f;  }  printf("%d",m);  return 0;}

That's it.

Question 2: usaco 2014 Jan silver, recording the sczolympus

The usaco questions are all over Moe, especially those of Farmer John and Bessey.

(The memory is good. I want to go to the 8-way E7 8870 + 16 TB memory desktop! It's better to have million agricultural enterprises w9100! Top 500 Rank 500 in seconds, OK? The power consumption is a bit crazy. The heat dissipation is still up to liquid helium. The super frequency is over 5 GHz. I don't want to use 980. That's the deal. (Don't YY, OK ))

Translation (official question, address)
When you can only record one program at a time this problem is relatively straightforward.
When you can only record one program at a time, the question is quite straightforward.
The next program you shoshould record is always the program that ends soonest and has not yet started.
When recording the next program, it is clear that there is a policy that records the closest to the start time.
Unfortunately, if you use this approach to schedule the first tape and then again (after removing those programs already recorded) to schedule the second tape you may not be able to schedule everything you want.
However, if you use this method to record the first volume of tape (audio) as a schedule and then process the second volume, you may not be able to get the answer you want.
The simplest test case that demonstrates this is already strated below.
The simplest example is as follows:Track 1: |-| --------- | track 2: | --------- |-|If you put all of the small programs on the same track it becomes impossible to schedule the larger program. so an alternate approach is needed. if you put all short programs in one channel record, it is impossible to broadcast longer programs. one approach is to use dynamic programming. our state can be described as the last two programs that were recorded on each track.
One strategy is to use dynamic planning. The State is the last two state programs we can record.
We can attempt to put any program that starts later than those two programs on either track if it starts after the current program on that track ends. we can try to place the start time of each program after the end time of the last program of one of the audio tracks into this audio track. it is important, however, that we restrict to only programs that start after the last recorded programs on each track.
One important thing is that we must make the start time of the program later than the programs already on track.
Otherwise we may attempt to record the same program on both tracks which wocould incorrectly inflate the answer. otherwise, we may record two similar programs at the same time ). alternatively, there is a more efficient greedy algorithm that does correctly solve this problem.
However, there is a more convenient and quick greedy solution to this problem.
The algorithm works by considering programs in order of ascending end times, tracking what the last two programs recorded on each track were.
We need to sort each program in ascending order of the end time to track the last recorded programs on two vaginal audio channels.
If the program starts before either track's program finishes then the program cannot be scheduled.
If the program ends before the first program of the two channels ends, the program cannot be recorded.
If it fits on only one track it shoshould be scheduled there. otherwise the program shocould be greedily scheduled on the track with the later ending current program. if only one channel meets the requirements, it will be recorded. otherwise, it will be recorded at the end of the day. this approach is based on the idea that, considering the programs in this order, we shoshould always assign a program to a track if we can.
This idea is based on the sequence in which we can record recorded programs.
This is because all later tracks we will consider have a later start time and therefore further constrain the track.
This is because all the subsequent programs will delay the recording of the next program)
In the case that the program can fit on either track we shoshould assign to the track which already has the later ending program.
In this way, if a program can be recorded in two channels, it will be recorded in the channel that ends later (one thigh radio)
This may allow us to assign tracks that start earlier (and end later) in the future.
So that we can consider starting an earlier program.
Really wit... and then start shooting code.

Then I shot the video in 8 minutes, and the teacher gave me a question! It's nice to include 500000 in the data range! (Then the $ \ Text {o} \ left (n \ log {n} \ right) $ algorithm runs! Now! I! No! Seconds! Tears ...)

Sleeping. It's too late ~~

(Sending algorithm with no code left, and tens of thousands of moles in Chrysanthemum ~~~)

// I completed the Code with wit. Haha, haha. When I was so witty, could you please go to Qinglong mountain to eat figs? # Include <cstdio> # include <algorithm> struct nd {int S, E;} f [300]; int N, I, j, a, B, T; bool CMP (nd a, nd B) {return. E <B. e;} int main () {scanf ("% d", & N); for (I = 0; I <n; ++ I) {scanf ("% d", & A, & B); F [I]. S = A; F [I]. E = B;} STD: Sort (F, F + N, CMP); a = B = 0; for (I = 0; I <n; ++ I) {T = f [I]. s; If (T <a) continue; // if F is earlier than we might record, skip it if (T <B) {A = B; B = f [I]. e; ++ J;} else {B = f [I]. e; ++ J ;}} printf ("% d", J); Return 0 ;}

 

Click farming question (1)

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.