HDU 5334 Virtual Participation

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

Input

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

Output

For 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

4
1 2 3 4

Author

XJZX

Source

2015 Multi-University Training Contest 4

#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);
    }
}

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

时间: 2024-08-03 22:44:07

HDU 5334 Virtual Participation的相关文章

HDU 5334 Virtual Participation(2015多校第四场)

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 

HDU 5334(Virtual Participation-(A+C+1)(B+C+1)=K+(1+C)^2-C)

Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 886    Accepted Submission(s): 257 Special Judge Problem Description As we know, Rikka is poor at math. Yuta is worrying ab

HDU 3172 Virtual Friends 带权并查集 -秩

ll T; while(~scanf("%d",&T)){ while(T--) { = = ... 思路: 用秩合并,看了题解才发现 if(fx == fy)要输出当前集合的秩而不是0... #include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <map&

HDOJ 5534 Virtual Participation 构造

构造 小于10^5的直接输出1 大于10^5的构造如下的串 1111...12222...233....3.....t,t+1,t+2.. 设长度为n,每种字符出现了L[i]次则不同的串有  n*n+n-sigma(L[i])=2*K 大约估计一个n,用贪心求出L Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi

hdu 3172 Virtual Friends (并查集 + 字典树)

题目: 链接:点击打开链接 题意: 输入n,给出n行数据,每行有两个字符串,输出关系网络中朋友的个数,n行. 思路: 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; const int N = 22; const int M = 200020; struct node { int c; node *chil

解题报告 之 HDU5334 Virtual Participation

解题报告 之 HDU5334 Virtual Participation 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 , she needs to come up wit

HDU 3172 Virtual Friends (map+并查集)

These days, you can do all sorts of things online. For example, you can use various websites to make virtual friends. For some people, growing their social network (their friends, their friends' friends, their friends' friends' friends, and so on), h

hdu 3172 Virtual Friends

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3172 并查集的运用... 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<map> 6 using std::map; 7 using std::string; 8 const int Max_N = 100010

HDU 3172 Virtual Friends(带权并查集)

题目地址:HDU 3172 带权并查集水题.每次合并的时候维护一下权值.注意坑爹的输入.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #inclu