HDU 5334 Virtual Participation,hdu5334

來源:互聯網
上載者:User

HDU 5334 Virtual Participation,hdu5334

簡單構造,設數列為1,1,...,1,2,2,...,2,3,3,....,3

設有 x 個1,y 個 2, z 個 3,枚舉x,y即可。

 不同的連續子序列有x + y + z + x*y + y*z + x*z。。。。

因為事實上K<=10^9時,最小的合法的 x 也不超過100.。。 

所以複雜度遠遠沒有想象中那麼高。。。。。

Virtual ParticipationTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 237    Accepted Submission(s): 56
Special Judge


Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he asks rikka to have some practice on codeforces. Then she opens the problem B:

Given an integer K, she needs to come up with an sequence of integers A satisfying that the number of different continuous subsequence of A is equal to k.

Two continuous subsequences a, b are different if and only if one of the following conditions is satisfied:

1. The length of a is not equal to the length of b.

2. There is at least one t that at≠bt, where at means the t-th element of a and bt means the t-th element of b.

Unfortunately, it is too difficult for Rikka. Can you help her? 
InputThere are at most 20 testcases,each testcase only contains a single integer K (1≤K≤109) 
OutputFor each testcase print two lines.

The first line contains one integers n (n≤min(K,105)).

The second line contains n space-separated integer Ai (1≤Ai≤n) - the sequence you find. 
Sample Input
10
 
Sample Output
41 2 3 4
 
AuthorXJZX 
Source2015 Multi-University Training Contest 4 

#include <bits/stdc++.h>using namespace std;#define prt(k) cerr<<#k" = "<<k<<endlconst int N = 100000;int main(){    int K;    while (scanf("%d", &K)==1) {        if (K<=2)        {            if (K==1) puts("1\n1");            if (K==2) puts("2\n1 1");            continue;        }        bool f = 1;        for (int x=0;f && x<=1e5;x++) {            for (int y=0;x+y<=1e5&&x+y+x*y<=K&&y<=sqrt(K+0.5);y++)            {                int t = K - x - y - x * y;                if (t % (x+y+1)==0) {                    int z = t / (x + y + 1);                    if (z < 0 || x+y+z>min(N, K)) continue;                    assert(x+y+z+x*y+y*z+x*z==K);                                       int n = x + y + z;                    printf("%d\n", n);                    for (int i=1;i<=n;i++) {                        int c;                        if (i<=x) c=1;                        else {                            if (i<=x+y) c = 2;                            else c = 3;                        }                        printf("%d%c", c, i==n ? 10 : ' ' );                    }                    f =false;                    break;                }            }        }        assert(!f);    }}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.