码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5334 Virtual Participation

时间:2015-07-31 10:48:36      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

简单构造,设数列为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 Participation

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


Problem Description
As 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 atbt, 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?
 

Input
There are at most 20 testcases,each testcase only contains a single integer K (1K109)
 

Output
For each testcase print two lines.

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

The second line contains n space-separated integer Ai (1Ain) - the sequence you find.
 

Sample Input
10
 

Sample Output
4 1 2 3 4
 

Author
XJZX
 

Source
 


#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
const 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);
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5334 Virtual Participation

标签:

原文地址:http://blog.csdn.net/oilover/article/details/47164727

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!