UVa 11330 (decomposition of the replacement cycle) Andy's Shoes

Source: Internet
Author: User

And UVa11077 's analysis is very similar.

We fixed the shoes on our left foot, and then we considered the shoes of the right foot as a substitution decomposition.

For a circular section with a length of L, swap to the correct position at least L-1 times.

1#include <cstdio>2#include <cstring>3#include <map>4 using namespacestd;5 6 BOOLvis[10000+Ten];7 8 intMain ()9 {Ten     //freopen ("In.txt", "R", stdin); One  A     intT; -scanf"%d", &T); -      while(t--) the     { -         intN, a, B; -map<int,int>m; -scanf"%d", &n); +          for(inti =0; I < n; i++) -         { +scanf"%d%d", &a, &b); AM[a] =b; at         } -         intAns =0; -map<int,int>:: iterator It; -memset (Vis,false,sizeof(Vis)); -          for(It = M.begin (); It! = M.end (); it++) -         { in             inti = it->First ; -             if(!Vis[i]) to             { +                 intCNT =0; -                 intj =i; the                  Do *                 { $cnt++;Panax NotoginsengVIS[J] =true; -j =M[j]; the} while(J! =i); +Ans + = cnt-1; A             } the         } +printf"%d\n", ans); -     } $  $     return 0; -}
code June

UVa 11330 (decomposition of the replacement cycle) Andy's Shoes

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.