• Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心


    A. Vanya and Cubes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.

    Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

    Input

    The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

    Output

    Print the maximum possible height of the pyramid in the single line.

    Examples
    input
    1
    output
    1
    input
    25
    output
    4
    Note

    Illustration to the second sample:

    题意:给你n个方块 按照如图的方式摆放 问最多能摆放多少层?

    题解:暴力层数 判断需要多少方块

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #define ll __int64
    15 using namespace std;
    16 int n;
    17 int a[10004];
    18 int main()
    19 {
    20     scanf("%d",&n);
    21     int sum=0;
    22     for(int i=1;i<=50;i++)
    23     {
    24         sum=sum+i*(i+1)/2;
    25         if(sum==n)
    26         {
    27             cout<<i<<endl;
    28             return 0;
    29         }
    30         if(sum>n)
    31         {
    32             cout<<i-1<<endl;
    33             return 0;
    34         }
    35     }
    36     return 0;
    37 }
    B. Vanya and Lanterns
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.

    Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

    Input

    The first line contains two integers nl (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.

    The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

    Output

    Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

    Examples
    input
    7 15
    15 5 3 7 9 14 0
    output
    2.5000000000
    input
    2 5
    2 5
    output
    2.0000000000
    Note

    Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment[3, 5]. Thus, the whole street will be lit.

     题意:l长的路 给你n个路灯的坐标 问你最小的路灯照射半径使得路上都被照亮

     题解:寻找最长的路灯间隔/2 并与第一个路灯,最后一个路灯照射的边界比较取最大值输出

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #define ll __int64
    15 using namespace std;
    16 int n,l;
    17 double a[1005];
    18 int main()
    19 {
    20     scanf("%d %d",&n,&l);
    21     for(int i=0;i<n;i++)
    22         scanf("%lf",&a[i]);
    23     sort(a,a+n);
    24     double minx=0;
    25     for(int i=1;i<n;i++)
    26     {
    27         if(a[i-1]==a[i])
    28             continue;
    29         minx=max(minx,a[i]-a[i-1]);
    30     }
    31     minx=max(minx/2.0,max(a[0],l-a[n-1]));
    32     printf("%f
    ",minx);
    33     return 0;
    34 }
    C. Vanya and Exams
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.

    What is the minimum number of essays that Vanya needs to write to get scholarship?

    Input

    The first line contains three integers nravg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

    Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r1 ≤ bi ≤ 106).

    Output

    In the first line print the minimum number of essays.

    Examples
    input
    5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5
    output
    4
    input
    2 5 4
    5 2
    5 2
    output
    0
    Note

    In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

    In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

    题意:n门科目 每门满分r 要求所有科目的均分大于等于avg才能获得奖学金  

    对于每门科目都有两个值 a为得分 b为每增加一分需要看的文章的数量 输出想要获得奖学金 需要看的文章的数量的最小值

    题解:贪心策略 对于每门科目按照b升序排  

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #define ll __int64
    15 using namespace std;
    16 ll n,r,avg;
    17  struct node
    18 {
    19     ll a,b;
    20 }N[100005];
    21 bool cmp(struct node aa,struct node bb)
    22 {
    23     return aa.b<bb.b;
    24 }
    25 int main()
    26 {
    27     scanf("%I64d %I64d %I64d",&n,&r,&avg);
    28     ll sum=0;
    29     for(int i=0;i<n;i++)
    30      {
    31          scanf("%I64d %I64d",&N[i].a,&N[i].b);
    32          sum+=N[i].a;
    33      }
    34      if(avg*n<=sum)
    35      {
    36          printf("0
    ");
    37          return 0;
    38      }
    39      sum=avg*n-sum;
    40      sort(N,N+n,cmp);
    41      ll ans=0;
    42      for(int i=0;i<n;i++)
    43      {
    44          ll exm=N[i].a;
    45          if(exm==r)
    46             continue;
    47          if(sum>=(r-exm))
    48          {
    49              ans=ans+(r-exm)*N[i].b;
    50              sum=sum-(r-exm);
    51          }
    52          else
    53          {
    54              ans=ans+sum*N[i].b;
    55              sum=0;
    56          }
    57          if(sum==0)
    58             break;
    59      }
    60      printf("%I64d
    ",ans);
    61     return 0;
    62 }
  • 相关阅读:
    2019CSUST集训队选拔赛题解(二)
    2019CSUST集训队选拔赛题解(一)
    Dilworth定理
    直线石子合并(区间DP)
    后缀自动机 个人学习笔记
    HDU_6709 CCPC网络赛H 优先队列 贪心
    2019省赛翻车记
    【挖坑】某场组队训练找到的想要挖一挖的东西
    暑假补题需要点的技能点
    QAQorz的训练记录
  • 原文地址:https://www.cnblogs.com/hsd-/p/5858078.html
Copyright © 2020-2023  润新知