Codeforces Round #259 (Div. 2) 题解_html/css_WEB-ITnose

A. Little Pony and Crystal Mine

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n matrix with a diamond inscribed into it.

You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character “D”. All other cells of the matrix should be represented by character “*”. Look at the examples to understand what you need to draw.

Input

The only line contains an integer n (3?≤?n?≤?101; n is odd).

Output

Output a crystal of size n.

立即学习“前端免费学习笔记(深入)”;

Sample test(s)

input

output

  1. *D*DDD*D*

登录后复制

input

output

  1. **D***DDD*DDDDD*DDD***D**

登录后复制

input

output

  1. ***D*****DDD***DDDDD*DDDDDDD*DDDDD***DDD*****D***

登录后复制

传送门:点击打开链接

解题思路:

水题,推出公式,直接打印即可。

代码:

  1. #include #include using namespace std;int main(){ int n; scanf("%d", &n); for(int i = 1; i

    B. Little Pony and Sort by Shift

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    One day, Twilight Sparkle is interested in how to sort a sequence of integers a1,?a2,?...,?an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:

    a1,?a2,?...,?an?→?an,?a1,?a2,?...,?an?-?1.

    Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?

    Input

    The first line contains an integer n (2?≤?n?≤?105). The second line contains n integer numbers a1,?a2,?...,?an (1?≤?ai?≤?105).

    Output

    If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.

    Sample test(s)

    input

    22 1
  2. 登录后复制

  3. output

  4. input

  5. 31 3 2
  6. 登录后复制

  7. output

  8. -1
  9. 登录后复制

  10. input

  11. 21 2
  12. 登录后复制

  13. output

  14. 题意:

  15. 给一个序列,每次可以把序列的最后一个数移到最前面,如果可以使序列递增(严格来说是非递减),输入最少移动次数,否则,输出-1;

  16. 解题思路:

  17. 先将序列扫一遍,遇到非递增的位置(记为t)跳出,接着从从t+1开始扫一遍,如果,后面的序列递增,则输出其长度,即为答案,否则,输出-1。因为如果要按照题中所述方式移动,使序列变为递增,序列应当是本来就是递增的,或者是可以分为两个连续的递增子序列的。

  18. 传送门:点击打开链接

  19. 代码:

  20.  
  21. #include #include #include using namespace std;const int MAXN = 1e5 + 10;int n, a[MAXN];int main(){    scanf("%d", &n);    for(int i  = 0; i  a[i+1]) break;    }    if(i != n-1)    {        for(int i = t+1; i  a[(i+1)%n])            {                flag = false;                break;            }        }    }    if(flag)    printf("%d\n", ans);    else    printf("-1\n");    return 0;}
  22. 登录后复制

  23. C. Little Pony and Expected Maximum

  24. time limit per test

  25. 1 second

  26. memory limit per test

  27. 256 megabytes

  28. input

  29. standard input

  30. output

  31. standard output

  32. Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

  33. The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains mdots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

  34. Input

  35. A single line contains two integers m and n (1?≤?m,?n?≤?105).

  36. Output

  37. Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10??-?4.

  38. Sample test(s)

  39. input

  40. 6 1
  41. 登录后复制

  42. output

  43. 3.500000000000
  44. 登录后复制

  45. input

  46. 6 3
  47. 登录后复制

  48. output

  49. 4.958333333333
  50. 登录后复制

  51. input

  52. 2 2
  53. 登录后复制

  54. output

  55. 1.750000000000
  56. 登录后复制

  57. 传送门: 点击打开链接

  58. 解题思路:

  59. 求数学期望,公式P = m - (1/m)^n - (2/m)^n - ... -((m-1)/m)^n

  60. 代码:

  61. #include #include #include int main(){    int m, n;    scanf("%d%d", &m, &n);    double ans = m;    for(int i = 1; i     


  62. 登录后复制

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    编程技术

    <span>有什么用?_html/css_WEB-ITnose

    2025-3-28 13:45:37

    编程技术

    在有网页源码的情况下,如何判断网页是给mobile用的网页_html/css_WEB-ITnose

    2025-3-28 13:45:41

    0 条回复 A文章作者 M管理员
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索