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 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 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); }}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。