zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 4 hdu 5334 Virtual Participation

    Virtual Participation

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 705    Accepted Submission(s): 202
    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 #include <bits/stdc++.h>
     2 using namespace std;
     3 int calc(int k) {
     4     int ret = 1;
     5     while(ret*(ret+1)/2 < k) ++ret;
     6     return ret;
     7 }
     8 int calc2(int x) {
     9     int ret = 1;
    10     while(ret*(ret-1)/2 <= x) ++ret;
    11     return ret-1;
    12 }
    13 int main() {
    14     int k;
    15     while(~scanf("%d",&k)) {
    16         if(k <= 100000) {
    17             printf("%d
    ",k);
    18             for(int i = 1; i < k; ++i)
    19                 printf("1 ");
    20             puts("1");
    21             continue;
    22 
    23         }
    24         int n = calc(k);
    25         int b = n*(n+1)/2 - k;
    26         int cnt = 0,d = 1;
    27         printf("%d
    ",n);
    28         while(b > 0) {
    29             int e = calc2(b);
    30             for(int i = 0; i < e; ++i) {
    31                 printf("%d%c",d,cnt+1==n?'
    ':' ');
    32                 cnt++;
    33             }
    34             b -= e * (e - 1) / 2;
    35             d++;
    36         }
    37         for(; cnt < n; ++cnt)
    38             printf("%d%c",d++,cnt+1==n?'
    ':' ');
    39     }
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    bbs小项目整理(八)(总结、源码分享)
    struts2验证框架
    Struts2文件上传例子
    struts2的参数的封装形式
    struts2的获取Servlet API的几种方式的学习笔记
    struts2的相关配置信息
    java向mysql插入时间,时间日期格式化
    关于将项目导入eclipse出现小红叉的解决笔记
    bbs小项目整理(七)(消息分页展现)
    HTML引用CSS
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4698926.html
Copyright © 2011-2022 走看看