博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015 多校联赛 ——HDU5334(构造)
阅读量:6087 次
发布时间:2019-06-20

本文共 2367 字,大约阅读时间需要 7 分钟。

 

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

 

 

假设用1,1...2,2....3,3....来构造,设他们的数量分别为 x    y     z

则能构成: x + y + z + x*y + y*z + x*z   (  x * z   代表三种数都包含的情况)

枚举  x  与   y  ,再判断z是否符合         (方法来源:http://blog.csdn.net/oilover/article/details/47164727)

P:  果然还是太弱,完全没想到╮(╯▽╰)╭,慢慢学,慢慢学

 

#include 
#include
#include
#include
#include
#include
int MAX=0x3f3f3f3f;using namespace std;const int INF = 0x7f7f7f;const int MAXM = 12e4+5;int ma = 100000;int main(){ int x,y,z,k; while(~scanf("%d",&k)) { if(k == 1) { printf("1\n1\n"); continue; } if(k == 2) { printf("2\n1 1\n"); continue; } int flag = 1; if(k <= 100000) { for(int i = 1; i < k; i++) printf("%d ",1); printf("1\n"); continue; } for(x = 0; x<= 1e5 &&flag ; x++) for(y = 0; x+y<=1e5 && y <= sqrt(k+0.5) && flag; y++) { int t = k - x - y - x*y; if(t % (x + y + 1) == 0) { z = t / (x +y +1); if(z < 0 || x + y + z > min(k,ma)) continue; int n = x + y + z; printf("%d\n",n); for(int i = 1; i <= n; i++) { if(i <= x) printf("1 "); else { if(i <= x + y) printf("2 "); else if(i < n) printf("3 "); else printf("3\n"); } flag = 0; } } } } return 0;}

  

转载于:https://www.cnblogs.com/Przz/p/5409807.html

你可能感兴趣的文章
阿里云公共镜像、自定义镜像、共享镜像和镜像市场的区别 ...
查看>>
shadowtunnel v1.7 发布:新增上级负载均衡支持独立密码
查看>>
Java线程:什么是线程
查看>>
mysql5.7 创建一个超级管理员
查看>>
【框架整合】Maven-SpringMVC3.X+Spring3.X+MyBatis3-日志、JSON解析、表关联查询等均已配置好...
查看>>
要想成为高级Java程序员需要具备哪些知识呢?
查看>>
带着问题去学习--Nginx配置解析(一)
查看>>
onix-文件系统
查看>>
java.io.Serializable浅析
查看>>
我的友情链接
查看>>
多线程之线程池任务管理通用模板
查看>>
CSS3让长单词与URL地址自动换行——word-wrap属性
查看>>
CodeForces 580B Kefa and Company
查看>>
开发规范浅谈
查看>>
Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming
查看>>
鼠标增强软件StrokeIt使用方法
查看>>
本地连接linux虚拟机的方法
查看>>
某公司面试java试题之【二】,看看吧,说不定就是你将要做的题
查看>>
BABOK - 企业分析(Enterprise Analysis)概要
查看>>
Linux 配置vnc,开启linux远程桌面
查看>>