首页 > 其他分享 >Codeforces Round #280 (Div. 2) A B C

Codeforces Round #280 (Div. 2) A B C

时间:2023-03-03 13:02:47浏览次数:45  
标签:Vanya output int Codeforces grade input 280 Div include

http://codeforces.com/contest/492

A 水题

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.

Sample test(s) input 1 output 1 input 25 output 4 Note

Illustration to the second sample:

Codeforces Round #280 (Div. 2) A B C_算法


#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>

using namespace std;

int n,m;

int a[1000];

int main ()
{
    a[1] = 1;
    for(int i=1;i<=999;i++)
        a[i] = a[i-1]+i;
    while (cin>>n)
    {
        int i =1;
        int ans = 0;
        while (n-a[i] >=0)
        {
            n-=a[i];
            i++;
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


B 简单贪心 


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.

Sample test(s) 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.


#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>

using namespace std;

int n,l;
double a[1010];

int main ()
{
    while (cin>>n>>l)
    {
          for(int i=1;i<=n;i++)
                cin>>a[i];
          sort(a+1,a+1+n);

          double ans = a[1] ;

          for(int i=1;i<=n-1;i++)
          {
              ans = max (ans,(a[i+1]-a[i])*1.0/2);
          }

          ans = max(ans,l-a[n]);

          printf("%.10lf\n",ans);
    }
    return 0;
}


C 按照bi升序排列 注意不要超时即可


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 ≤ r, 1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Sample test(s) 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.



#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>

using namespace std;

int n;
long long r;
long long avg,AVE;

struct q
{
    int a;
    int b;
}p[100010];

bool cmp(q aa,q bb)
{
    return aa.b < bb.b;
}

int main ()
{
    while (cin>>n>>r>>avg)
    {
        AVE= 0;
        for(int i=1;i<=n;i++)
        {
            cin>>p[i].a>>p[i].b;
            AVE+=p[i].a;
        }

        if (AVE >= avg*n)
        {
            cout<<0<<endl;
            return 0;
        }

        sort(p+1,p+1+n,cmp);

        long long  ans = 0;

        int i = 1;
        while ( AVE < avg*n )
        {
            ans += p[i].b * min ( r -p[i].a,n*avg - AVE );
            
            AVE += min(r -p[i].a,n*avg - AVE);

            i++;
        }

        cout<<ans<<endl;
                    
    }

    return 0;
}









标签:Vanya,output,int,Codeforces,grade,input,280,Div,include
From: https://blog.51cto.com/u_15990681/6098480

相关文章

  • Codeforces Round #281 (Div. 2) A B
    http://codeforces.com/contest/493A第一次结构体开二维数组。。。A.VasyaandFootballtimelimitpertest2secondsmemorylimitper......
  • Codeforces Round #850 (Div. 2, based on VK Cup 2022 - Final Round)
    Preface补题,之前由于要准备开学考(其实只是临时抱佛脚罢了),所以好久没写题不过索性学校题目简单,微积分线代C程都满绩了(甚至溢出好多),思政被卡了一分满绩点,而大英不出所料3.7......
  • div水平垂直居中的四种方式
    div水平垂直居中的四种方式让div水平居中的方式,我所知道的就是以下这四种。目录div水平垂直居中的四种方式一、margin二、绝对定位三、子元素绝对定位父元素相对定位四、......
  • Educational Codeforces Round 55 (Rated for Div. 2) G. Petya and Graph 网络流|
    很经典,想记录一下网络流里有一个很典的trick,求最大获利转化成最小损失求最小损失转化成割边求的是max(边权和-边所连接的点权和),考虑把边看成左部点,把点看成右部点刚开......
  • Educational Codeforces Round 144 (Rated for Div. 2)
    链接EducationalCodeforcesRound144(RatedforDiv.2)只会两个题太弱了A题先打表找出一个很长的字符字串然后,用strstr查找找到yes找不到no#include<iostream>......
  • Codeforces 438D The Child and Sequence 势能线段树
    势能线段树|拉线段树题单时发现的这道花神游历各国的骚操作至今让我印象深刻,原来有名字所谓势能,大意就是原本你在高空,操作一点下降一点,势能变少一点..当你落地时,修改......
  • ABC-280解题报告
    D.FactorialandMultiple题意:给你一个\(k\),求最小的\(n\)使得\(k|n!\)。\(k\le10^{12}\)。做法一考虑将\(k\)分解质因数,对于每项\(p^r\),都要求\(n!\)中含......
  • CFR-826-Div-3解题报告
    F.Multi-ColoredSegments题意:数轴上有\(n\)个线段,每个区间有一个颜色\(c\),对于每个线段,求与它颜色不同的线段中与它的最短距离。距离定义为两个线段中的点集最近的......
  • CFR-832-Div-2解题报告
    B.BANBAN题意:给你一个\(n\),生成一个字符串为BAN重复\(n\)遍。每次操作可以选择两个位置进行交换,问至少多少次交换后可以使该串不存在BAN的子序列。输出方案。......
  • CFR-755-Div-2解题报告
    比赛传送门赛时AC三道,补题做出一道。A.MathematicalAddition{%noteinfono-iconProblem%}给你两个正整数\(u,v\),求一对合法的\(x,y\)使得\(\frac{x}{u}+\fra......