2015 Multi-University Training Contest 4(hdu5334 - Virtual Participation)数学
2015-08-01 16:58
309 查看
Virtual Participation
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:
The length of a is not equal to the length of b.
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≤1091≤K≤10^9)Output
For each testcase print two lines.The first line contains one integers n(n≤min(K,105))n (n\leq min(K,10^5)).
The second line contains n space-separated integer Ai (1≤Ai≤n) - the sequence you find.
Sample Input
10Sample Output
4
1 2 3 4
[code]#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> using namespace std; typedef long long LL; const int maxn=100010; const int maxm=1010; const int MOD=1e9+7; const int INF=0x3f3f3f3f; int K; int len[maxn]; int main() { while(scanf("%d",&K)!=EOF) { if(K<=100000) { printf("%d\n",K); for(int i=1;i<K;i++) printf("%d ",1); printf("1\n"); continue; } int N=ceil((sqrt(8*(LL)K-1)-1)/2); int cnt=0,num=0; LL d=N*N+N-2*K; while(d) { int L=int(sqrt(1+4*d*1.0)+1)/2; len[++num]=L; cnt+=L; d-=(LL)L*(L-1); } printf("%d\n",N); for(int i=1;i<=num;i++) { for(int j=1;j<=len[i];j++) printf("%d ",i); } if(cnt<N) { //减掉相同的剩下的还差的不同的补全 for(int j=1;j<=N-cnt;j++) printf("%d ",num+j); } printf("\n"); } return 0; }
相关文章推荐
- HDU 2473 Junk-Mail Filter (并查集节点删除)
- activity_main cannot be resolved or is not a field
- 解决Visual Studio 2015创建工程时的“DNX SDK version 'dnx-clr-win-x86.1.0.0-beta5' failed to install.”错误
- HUAS Summer Trainning #3 C
- iWatch报错: Fail to code sign "***" No valid signing identities (i.e. certificate and private key pair
- hdu1789doing homework again【贪心】
- 2015 Multi-University Training Contest 4(HDOJ5327、5328、5335、5536)
- HUAS Summer Trainning #3 B
- Climbing Stairs
- HUAS Summer Trainning #3 A
- hdu5319 Painter
- 处理Block中的self问题(Capturing 'self' strongly in this block is likely to lead to a retain cycle)
- Paint及Canvas的简单应用
- http://blog.csdn.net/hellowxwworld/article/details/10720765
- hdu1839Delay Constrained Maximum Capacity Path 二分+最短路
- Tomcat全局/局部https访问配置方法【tomcat容器的配置文件web.xml中添加security-constraint】
- 2015 Multi-University Training Contest 3(HDOJ5316、5317、5319、5326)
- 利用playfair置换实现密钥加密
- 安装 rails 失败
- Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException