URAL 2019 Pair:normal and Paranormal (greedy)-gdut United Seventh Field

Source: Internet
Author: User

Contest Topic Link

Test Instructions: There are n individuals each holding a gun trying to kill N Monsters, capital letters representing people, and small letters representing monsters. a can only kill a,b can only kill B, as shown in the picture in the title, the gun trajectory can not cross . The numbers of people and monsters are 1 to n, and ask if there is a case that kills all, and if it does, the number of each person killed by the output number 1 to n , if not output " Impossible".

The following: greedy, with recursive implementation, to determine whether the adjacent can constitute a pair, priority to form adjacent, if not recursive to the front to see if it can constitute a pair can.

#include <cstdio>#include<cstring>#include<queue>using namespacestd;intn,e;Chardata[5005*2];intnext[5005*2];BOOLeqCharACharb) {BOOLTa=0, tb=0; if(a>='A'&&a<='Z') {a-='A'; Ta=1; }    if(a>='a'&&a<='Z') a-='a'; if(b>='A'&&b<='Z') {b-='A'; TB=1; }    if(b>='a'&&b<='Z') b-='a'; if(TA&AMP;&AMP;TB)return false; if(ta==false&& tb==false)return false; returna==b;}voidSolveints) {//printf ("%d%d\n", s,e);e++; if(e>=n)return;  while(e<n&&!eq (data[s],data[e]))    {Solve (E); }    if(e>=n)return; Next[s]=e; Next[e]=s; E++;}intMain () {scanf ("%d",&N); scanf ("%s", data); N*=2; memset (Next,-1,sizeof(Next)); E=0;  while(e<=N) solve (e);  for(intI=0; i<n;i++) {        //printf ("%d", Next[i]);        if(next[i]==-1) {puts ("Impossible"); return 0; }    }    //puts ("");    intgid[5005*2],g=1;  for(intI=0; i<n;i++) {        if(data[i]>='a'&&data[i]<='Z') {Gid[i]= g++; }    }     for(intI=0; i<n;i++) {        if(data[i]>='A'&&data[i]<='Z') {printf ("%d", Gid[next[i]]); }} puts ("");}

URAL 2019 Pair:normal and Paranormal (greedy)-gdut United seventh Field

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.