A. Vanya and Cubes

题意:

给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔。

分析:

根据求和公式,有,按照规律直接加就行,直到超过n。

 #include <cstdio>

 int main()
{
int n;
scanf("%d", &n);
int sum = , cnt = ;
while(n > sum)
{
cnt++;
sum += cnt * (cnt + ) / ;
}
if(sum > n) cnt--;
printf("%d\n", cnt); return ;
}

代码君

B. Vanya and Lanterns

题意:

有一条长为l的路,每个灯的坐标为ai(坐标原点为路的最左端),每个路灯照亮的范围为d,要求整条路都能被照亮,求d的最小值。

分析:

上来写个了二分,果断超时了。

换个思路:

对这n个路灯的位置排序

因为d要照亮整条路,所以要满足:

  • 第一个路灯要照亮路的最左端,d至少为 a0
  • 两个相邻路灯之间要被照亮,d至少为(ai - ai-1) / 2
  • 最后一个路灯要照亮路的最右端,d至少为 l - an-1

要同时满足这些条件,取其中最大值即可。

 #include <cstdio>
#include <algorithm> const int maxn = + ;
double a[maxn], l;
int n; int main()
{
scanf("%d%lf", &n, &l);
for(int i = ; i < n; ++i) scanf("%lf", &a[i]);
std::sort(a, a + n); double ans = a[] - ;
for(int i = ; i < n; ++i)
{
ans = std::max(ans, (a[i]-a[i-])/);
}
ans = std::max(ans, l - a[n-]);
printf("%.10f\n", ans); return ;
}

代码君

C. Vanya and Exams(贪心)

题意:

有n门科目满分为r,每门科目现有分数为ai,每提高该科目一分需要写bi篇文章。为了要使平均分不低于avg,求写文章的最少篇数。

分析:

很明显的贪心,计算出一个还需要提高的分数,在不超过满分的前提下先提高bi小的科目的分数。

 #include <cstdio>
#include <algorithm> const int maxn = + ; typedef __int64 LL; struct Exam
{
LL a, b;
Exam(LL a=, LL b=):a(a), b(b) {}
bool operator < (const Exam& rhs) const
{
return b < rhs.b;
}
}exam[maxn]; int main()
{
LL n, r, avg, sum = ;
scanf("%I64d%I64d%I64d", &n, &r, &avg);
for(int i = ; i < n; ++i)
{
LL a, b;
scanf("%I64d%I64d", &a, &b);
sum += a;
exam[i] = Exam(a, b);
}
std::sort(exam, exam + n); LL ans = , p = ;
LL need = n * avg - sum;
while(need > )
{
if(exam[p].a == r) { p++; continue; }
LL temp = std::min(need, r - exam[p].a);
ans += temp * exam[p].b;
need -= temp;
p++;
}
printf("%I64d\n", ans); return ;
}

代码君

D. Vanya and Computer Game(数论)

题意:

题意没弄清,结果无限WA

有两个人每次对怪物造成1点伤害,怪物的血量为a。

他们两人的每秒攻击次数分别为x、y,而且攻击时间均匀分布在这1秒内

问打败该怪物时,是被谁打败的,还是同时被两个人打败的。

分析:

首先我们化小数为整数,不妨将1秒均匀分成xy份单位时间

则两人分别每隔y、x个单位时间攻击一次,对怪物造成1点伤害

我们得到两人每次攻击时间的序列

y, 2y, 3y,,,,,,

x, 2x, 3x,,,,,,

有序合并两个序列,我们就能知道怪物是被谁打到的。

可以用一个标记数组0、1、2来记录第i次攻击是第一个人、第二个人、两人同时发起的。

不难发现其实标记数组是循环的,所以只要求出其中一个循环节即可。

循环节长度为x/g + y/g,其中g = gcd(x, y),注意在两人同时发出攻击时,怪物是收到2点伤害的。

 #include <cstdio>

 typedef __int64 LL;
const int maxn = + ;
char flag[maxn]; LL gcd(LL a, LL b)
{
LL r = a % b;
while(r)
{
a = b;
b = r;
r = a % b;
}
return b;
} int main(void)
{
//freopen("in.txt", "r", stdin);
LL n, x, y;
scanf("%I64d%I64d%I64d", &n, &x, &y);
LL g = gcd(x, y);
LL p = , q = , cnt = ;
while(p <= y/g || q <= x/g)
{
if(x*p < y*q)
{
p++;
flag[cnt++] = ;
}
else if(x*p > y*q)
{
q++;
flag[cnt++] = ;
}
else
{
p++;
q++;
flag[cnt++] = ;
}
}
flag[] = flag[cnt] = ; for(int i = ; i < n; ++i)
{
LL a;
scanf("%I64d", &a);
a %= cnt;
if(flag[a] == ) puts("Vova");
else if(flag[a] == ) puts("Vanya");
else puts("Both");
} return ;
}

代码君

CodeForces Round #280 (Div.2)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 i ...

  5. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  6. Codeforces Round #280 (Div. 2)_C. Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. 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 ...

随机推荐

  1. 3244: [Noi2013]树的计数 - BZOJ

    Description 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的BFS序也有可能相同, ...

  2. reset内容

      /*reset */div,p,a,span,body,dl,dt,dd,header,footer,img,section,time,h2,em,article,h3,h4,ul,li,labe ...

  3. 6 个基于 jQuery 的表单向导插件推荐

    表单向导可以很好地引导用户进行一步一步的操作,从而降低用户错误输入的几率.尽管互联网中有大量的类似插件,但真正好用的不多. 本文整理了6个比较优秀的表单向导插件,希望能够为你带来帮助. 1. Smar ...

  4. 果盟广告SDK

    // // GuomobWallView.h // GuoMobWallSample // // Created by keyrun on 14-1-21. // Copyright (c) 2014 ...

  5. android2.3 -添加自定义按键:作唤醒功能 .

    最近需要做个唤醒功能,当按键的时候android系统唤醒并点亮屏,在长按键中,系统不能在进入睡眠. 驱动方面: 1:在平台设备文件中添加 一个按键,定义为唤醒源! \arch\arm\mach-s5p ...

  6. CC150 上面重要的题目总结

    第一章 : 全部重要 (1.6, 1.7 Leetcode上有). 1.5 面A碰到 (string compression) 1.7面Z碰到 (set 0) 1.8面Bigfish碰到 (strin ...

  7. 深入浅出ES6(二):迭代器和for-of循环

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 我们如何遍历数组中的元素?20年前JavaScript刚萌生时,你可能这样实现数 ...

  8. addListener添加事件监听器,第三个参数useCapture (Boolean) 的作用

    addEventListener 有三个参数:第一个参数表示事件名称(不含 on,如 "click"):第二个参数表示要接收事件处理的函数:第三个参数为 useCapture,本文 ...

  9. 系统学习sqlserver2012 一

    一:使用管理服务器和脚本 在试图菜单中选族已注册的服务器,可以直接切换登录服务器 在试图菜单中选择解决方案资源管理器,可以直接打开之前保存的脚本,方便管理和执行 这两种保存时,都可以分组保存,见下图

  10. redis、memcache、mongoDB有哪些区别(转载)

    转载: http://leandre.cn/database/64.html Memcached Memcached的优点: Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS ...