Codeforces 351B Jeff and Furik

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/351/B

Test instructions: Two person takes turns game, the initiator exchanges adjacent two number, the hand first throws the coin, the positive on the left big right small change, opposite right big left small to change, randomly finds a logarithm, until the entire sequence rises position, asks the minimum desired step number.

Idea: Because the first person each time will reduce a pair of reverse, then the hand will be 50% to reduce a pair, 50% increase a pair, we put two people together is:

50% reverse is unchanged, 50% decreases by 2

f[i]=f[i]*0.5+f[i-2]*0.5

Figure out is f[i]=f[i-2]+4, initial value: F[0]=0,f[1]=1

1#include <cstdio>2#include <cmath>3#include <cstring>4#include <algorithm>5#include <iostream>6 intn,a[3005],c[3005];7 intf[3005*3005];8 intRead () {9      intt=0, f=1;CharCh=GetChar ();Ten       while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} One       while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} A      returnt*F; - } - intLowbit (intx) { the      returnx& (-x); - } - voidAddintx) { -        for(inti=x;i;i-=lowbit (i)) { +c[i]++; -       } + } A intAskintx) { at       intres=0; -        for(inti=x;i<=n;i+=lowbit (i)) { -res+=C[i]; -       } -       returnRes; - } in intMain () { -N=read ();intans=0; to       for(intI=1; i<=n;i++) a[i]=read (); +       for(intI=1; i<=n;i++) ans+=ask (A[i]), add (A[i]); -f[0]=0; f[1]=1; the       for(intI=2; i<=ans;i++) f[i]=f[i-2]+4; *printf"%.6f\n",(Double) F[ans]); $}

Codeforces 351B Jeff and Furik

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.