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

假设用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 <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
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;
}

  

2015 多校联赛 ——HDU5334(构造)的更多相关文章

  1. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. 2015 多校联赛 ——HDU5353(构造)

    Each soda has some candies in their hand. And they want to make the number of candies the same by do ...

  3. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  5. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  6. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  8. 2015 多校联赛 ——HDU5301(技巧)

    Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...

  9. 2015 多校联赛 ——HDU5303(贪心)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

随机推荐

  1. Oracle查询用户权限

    Oracle查询用户权限 -- 确定角色的权限select * from role_tab_privs ;              包含了授予角色的对象权限select * from role_ro ...

  2. Linux进程间通信--信号量

    信号量绝对不同于信号,一定要分清,关于信号,上一篇博客中已经说过,如有疑问,请移驾! 信号量 一.是什么   信号量的本质是一种数据操作锁,它本身不具有数据交换的功能,而是通过控制其他的通信资源(文件 ...

  3. 在Nginx上配置多个站点

    有时候你想在一台服务器上为不同的域名运行不同的站点.比如www.siteA.com作为博客,www.siteB.com作为论坛.你可以把两个域名的IP都解析到你的服务器上,但是没法在Nginx的根目录 ...

  4. initializer element is not a compile-time constant

    初始化一个全局变量或static变量时,只能用常量赋值,不能用变量赋值! 如下就会报这个错误(KUIScreenWidth)是变量 static CGFloat const topButtonWidt ...

  5. Flask 学习 十五 性能

    记录影响性能的数据库查询 app/main/views.py from flask_sqlalchemy import get_debug_queries @main.after_app_reques ...

  6. 【bug清除】新Surface Pro使用OneNote出现毛刺现象的解决方案

    在写字的时候,左手触摸Surface的金属外壳背面,大概两个手指指肚大小.问题亲测可以得到解决. 推测是设备使用时接地没有做好,导致电磁笔出现偏移.问题初步锁定在新笔的倾斜感应上. 参考资料: htt ...

  7. Linux "零拷贝" sendfile函数中文说明及实际操作

    Sendfile函数说明 #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); sendfile ...

  8. New UWP Community Toolkit - DropShadowPanel

    概述 UWP Community Toolkit  中有一个为 Frmework Element 提供投影效果的控件 - DropShadowPanel,本篇我们结合代码详细讲解  DropShado ...

  9. Andrew Ng机器学习第一章——初识机器学习

    机器学习的定义 计算机程序从经验E中学习,解决某一任务T.进行某一性能度量P,通过P测定在T上的表现因E而提高. 简而言之:程序通过多次执行之后获得学习经验,利用这些经验可以使得程序的输出结果更为理想 ...

  10. Web Api 返回图片流

    public class TestController : ApiController { public HttpResponseMessage GetImg() { //获取文件的绝对路径 stri ...