1 second
256 megabytes
standard input
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.
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
1
1
25
4
Illustration to the second sample:
题意:给你n个方块 按照如图的方式摆放 问最多能摆放多少层?
题解:暴力层数 判断需要多少方块
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
int sum=;
for(int i=;i<=;i++)
{
sum=sum+i*(i+)/;
if(sum==n)
{
cout<<i<<endl;
return ;
}
if(sum>n)
{
cout<<i-<<endl;
return ;
}
}
return ;
}
1 second
256 megabytes
standard input
standard output
Vanya walks late at night along a straight street of length l, lit by n *s. 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 * is at the point ai. The * 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 *s.
Vanya wonders: what is the minimum light radius d should the *s have to light the whole street?
The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of *s and the length of the street respectively.
The next line contains n integers ai (0 ≤ ai ≤ l). Multiple *s can be located at the same point. The *s may be located at the ends of the street.
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.
7 15
15 5 3 7 9 14 0
2.5000000000
2 5
2 5
2.0000000000
Consider the second sample. At d = 2 the first * will light the segment [0, 4] of the street, and the second * will light segment[3, 5]. Thus, the whole street will be lit.
题意:l长的路 给你n个路灯的坐标 问你最小的路灯照射半径使得路上都被照亮
题解:寻找最长的路灯间隔/2 并与第一个路灯,最后一个路灯照射的边界比较取最大值输出
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n,l;
double a[];
int main()
{
scanf("%d %d",&n,&l);
for(int i=;i<n;i++)
scanf("%lf",&a[i]);
sort(a,a+n);
double minx=;
for(int i=;i<n;i++)
{
if(a[i-]==a[i])
continue;
minx=max(minx,a[i]-a[i-]);
}
minx=max(minx/2.0,max(a[],l-a[n-]));
printf("%f\n",minx);
return ;
}
1 second
256 megabytes
standard input
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?
The first line contains three integers n, r, avg (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).
In the first line print the minimum number of essays.
5 5 4
5 2
4 7
3 1
3 2
2 5
4
2 5 4
5 2
5 2
0
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升序排
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
ll n,r,avg;
struct node
{
ll a,b;
}N[];
bool cmp(struct node aa,struct node bb)
{
return aa.b<bb.b;
}
int main()
{
scanf("%I64d %I64d %I64d",&n,&r,&avg);
ll sum=;
for(int i=;i<n;i++)
{
scanf("%I64d %I64d",&N[i].a,&N[i].b);
sum+=N[i].a;
}
if(avg*n<=sum)
{
printf("0\n");
return ;
}
sum=avg*n-sum;
sort(N,N+n,cmp);
ll ans=;
for(int i=;i<n;i++)
{
ll exm=N[i].a;
if(exm==r)
continue;
if(sum>=(r-exm))
{
ans=ans+(r-exm)*N[i].b;
sum=sum-(r-exm);
}
else
{
ans=ans+sum*N[i].b;
sum=;
}
if(sum==)
break;
}
printf("%I64d\n",ans);
return ;
}
Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心的更多相关文章
-
Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
-
Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
-
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
-
Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
-
Codeforces Round #280 (Div. 2) E. Vanya and Field 数学
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...
-
Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分
D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
-
Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...
-
CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
-
Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...
随机推荐
-
我最常用的几个Xcode快键键
⌘(command) ⏎(return) ⌥(option/alt) ⇧(shift) ⌃(control/ctrl) 快速打开文件 ⌘ + ⇧ + O(字母) 快速搜索文本 ⌘ + ⇧ + F 分栏 ...
-
获得iOS设备唯一标识
使用-[UIDevice identifierForVendor]或是-[ASIdentifierManager advertisingIdentifier]来作为你框架和应用的唯一标示符.坦白的来说 ...
-
RequireJS的简单应用
一.RequireJS的主要作用与优点 主要作用:js模块化.编写复用js代码 优点: 1.防止命名冲突 2.声明不同js文件之间的依赖 3.代码模块化 (1)一个文件一个模块:每个js文件应该只定义 ...
-
cubla sample-code
cublasSscal //Example 1. Application Using C and CUBLAS: 1-based indexing #include <stdlib.h> ...
-
hdu 5459 Jesus Is Here 数学
Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
-
mac os 10.10 pod install errors
/System/Library/Frameworks/Ruby.framework/Versions//gems/rake-/bin/rake RUBYARCHDIR=/Library/Ruby/Ge ...
-
Apktool编译找不到“keyboardNavigationCluster”
喜欢用使用apktool来反编译.编译安卓程序,然后用其他工具来分析.签名.优化等,它比其他工具的优点是不易出错. 命令 反编译命令:apktool d -f XX.apk -o 反编译输出的目录(如 ...
-
DataSnap下的分包获取
DataSnap下通过TQuery—TDataSetProvider—TClientDataSet获取数据,如果是主从数据,则每条主表记录都会触发从表数据的获取. 这种获取和组织数据的方式有一个问题: ...
-
StanFord ML 笔记 第一部分
本章节内容: 1.学习的种类及举例 2.线性回归,拟合一次函数 3.线性回归的方法: A.梯度下降法--->>>批量梯度下降.随机梯度下降 B.局部线性回归 C.用概率证明损失函数( ...
-
ReadWriteLock
ReadWriteLock也是一个接口,只有两个方法 一个用来获取读锁,一个用来获取写锁.也就是说将文件的读写操作分开,分成2个锁来分配给线程,从而使得多个线程可以同时进行读操作.下面的Reentra ...