codeforcesAIM Tech Round 3 (Div. 2)

來源:互聯網
上載者:User
D

超級無敵的分類討論 題目大意

試構造一個串 aij a_{ij}為串中的ij序列的個數

厲害就厲害在這個處理上
先判斷各種無解
然後
先試著能不能放0
放0的條件是
1、 (dq0+1)∗(one−dq1)+dq01<=a01 (dq_0 + 1) * (one - dq_1) + dq_{01}
放完之後的維護是
2、 dq0=dq0+1,dq10=dq10+dq1 dq_0 = dq_0+1,dq_{10} = dq_{10} + dq_1

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 1000000 + 5;const int MAXL = 1000000; bool num[MAXN];int n;int a00,a01,a10,a11;int zero,one;int main(){    scanf("%d %d %d %d",&a00,&a01,&a10,&a11);    if(!a00 && !a01 && !a10 && !a11)    {        puts("0");        return 0;    }    for(zero = 0;zero <= MAXL + 1;zero ++)        if(zero * (zero - 1) == a00 * 2)            break;    for(one = 0;one <= MAXL + 1;one ++)        if(one * (one - 1) == a11 * 2)            break;    if(!zero && (a01 || a10))        zero++;    if(!one && (a01 || a10))one++;    if(zero + one > MAXL)    {        puts("Impossible");        return 0;    }    n = zero + one;    int dq0 = 0,dq1 = 0;    int dq01 = 0,dq10 = 0;    for(int i = 1;i <= n;i ++)    {        if((dq0 + 1) * (one - dq1) + dq01 <= a01)        {            num[i] = 0;            dq0 ++;            dq10 += dq1;            continue;        }        else        {            num[i] = 1;            dq1 ++;            dq01 += dq0;            continue;        }    }    if(dq01 != a01 || dq10 != a10)    {        puts("Impossible");        return 0;    }    for(int i = 1;i <= n;i ++)        printf("%d",num[i]);    puts("");    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.