Sort + Reverse Thinking Acdream 1205 disappeared Block

Source: Internet
Author: User
Tags cas

Topic Portal

1 /*2 from the big to the small sort, reverse thinking, from the last to consider, no-go sex3 each found a not submerged, to it about the floor of the query whether it is isolated, if + +, if not--4 complexity O (n + m), thought O (n^2) was scared to write half of it.5 */6#include <cstdio>7#include <cstring>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <string> - using namespacestd; -  the Const intMAXN = 1e6 +Ten; - Const intINF =0x3f3f3f3f; - structHight - { +     intVal, id; - }H[MAXN]; + intQ[MAXN]; A intVIS[MAXN]; at intANS[MAXN]; -  - BOOLCMP (Hight A, Hight b) - { -     returnA.val >B.val; - } in  - intMainvoid)//Acdream 1205 disappeared Block to { +     //freopen ("j.in", "R", stdin); -  the     intT; *     intN, M; $ Panax Notoginsengscanf ("%d", &t); -     intCAS =0; the      while(t--) +     { Amemset (Vis,0,sizeof(Vis)); thescanf ("%d%d", &n, &m); +          for(intI=1; i<=n; ++i) -         { $scanf ("%d", &h[i].val); $H[i].id =i; -         } -          for(intI=1; i<=m; ++i) scanf ("%d", &q[i]); the  -Sort (H +1, H +1+N, CMP);Wuyi  the         intCNT =0;intres =0; -          for(intI=1, J=m; j>=1; --j) Wu         { -              for(; i<=n; + +i) About             { $                 if(H[i].val <= q[j]) Break; -                 intpos =h[i].id; -Vis[h[i].id] =1; -                 if(!vis[pos-1] &&!vis[pos+1]) res++; A                 if(vis[pos-1] && vis[pos+1]) res--; +             } theANS[J] =Res; -         } $printf ("Case #%d:", ++CAs); the          for(intI=1; i<=m; ++i) printf ("%d%c", Ans[i], (i==m)?'\ n':' '); the     } the      the  -     return 0; in } the  the /* About Case #1:1 1 2 the Case #2:1 2 1 1 0 the */

Sort + Reverse Thinking Acdream 1205 disappeared Block

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.