Hdoj 4907 task schedule [preprocessing]

Source: Internet
Author: User

Question: Chinese question, you know...

Ideas:Create two arrays, one tag, and one answer (that is, the fastest task point to be processed). When you input data, Mark and change the location that already has a task, and find a maximum number of Max. Then, from Max + 1, start from big to small, and use temp to define the serial number without a task. If it is not marked, define the answer here as temp.

Click the link to open the question

Code:

# Include <stdio. h> # include <string. h> # define maxn 200005int vis [maxn], ANS [maxn]; int main () {int t, n, m, I, j, Q; scanf ("% d", & T); While (t --) {int A; memset (VIS, 0, sizeof (VIS); memset (ANS, 0, sizeof (ANS); int K = 0; int max = 0; scanf ("% d", & N, & M); for (I = 1; I <= N; I ++) {scanf ("% d", & A); vis [a] = 1; if (max <A) max = ;} int temp = MAX + 1; for (I = max; I> 0; I --) {If (vis [I]) ans [I] = temp; else temp = I ;} While (M --) {scanf ("% d", & Q); If (! Vis [Q]) {printf ("% d \ n", q) ;}elseprintf ("% d \ n", ANS [Q]) ;}} return 0 ;}


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.