You are not logged in. Please login at www.codechef.com to post your questions!

×

JHAGIRLS - AAO KABHI HAWELI PE :P

link text

CODE:

include<bits stdc++.h="">

using namespace std;

define li long long int

define vi vector
  • li ans, ok; vi arr; void bitmasking(li co, li rw, li lld, li rd) {

    if(rw==ok)
    {
        ++ans; return;
    }
    li pos=ok&(~(rw|lld|rd));
    while(pos)
    {
        li p=pos&-pos;
        pos-=p;
        bitmasking(co+1, (rw|p), (lld|p)<<1, (rd|p)>>1);
        if(ans)
        {
            arr[(int)(log2(p))]=co;
            return;
        }
    }
    

    } int main() {

    li t;
    cin>>t;
    li mark[101];
    vi mem[101];
    memset(mark, 0, sizeof mark);
    while(t--)
    {
        li n;
        cin>>n;
        if(!mark[n]){
        arr.clear();
        arr.assign(n+1, 0);
        ok=0, ans=0;
        ok=(1<<n)-1;
        bitmasking(1, 0, 0, 0);
        for(li i=0;i<n; ++i)
        mem[n].push_back(arr[i]);
        mark[n]=1;
        }
        for(li i=0;i<n; ++i)
        {
            cout<<i+1<<" "<<mem[n][i]<<endl;
        }
    }
    return 0;
    

    }

    This question is marked "community wiki".

    asked 14 Apr '17, 16:21

    junior_g's gravatar image

    3★junior_g
    444
    accept rate: 0%

    edited 14 Apr '17, 16:22

    toggle preview
    Preview

    Follow this question

    By Email:

    Once you sign in you will be able to subscribe for any updates here

    By RSS:

    Answers

    Answers and Comments

    Markdown Basics

    • *italic* or _italic_
    • **bold** or __bold__
    • link:[text](http://url.com/ "title")
    • image?![alt text](/path/img.jpg "title")
    • numbered list: 1. Foo 2. Bar
    • to add a line break simply add two spaces to where you would like the new line to be.
    • basic HTML tags are also supported
    • mathemetical formulas in Latex between $ symbol

    Question tags:

    ×1,134
    ×104
    ×7
    ×3

    question asked: 14 Apr '17, 16:21

    question was seen: 421 times

    last updated: 14 Apr '17, 16:22