Codeforces Round#280(Div.2)

新博客网址:http://qianyuge.com/

真是炫酷,诚然沾了题比较水的光,但是劳资4题撒

A题没什么好说的,枚举就好

#!/usr/bin/env python
# coding=utf-8

n = input()
ans = 0
tmp = 0
i = 1;
while True:
    tmp += i * (i + 1) / 2
    i += 1
    if tmp > n:
        break
    ans += 1;
print ans

B题更加是简单的很,排序之后撸一遍就行了,由于数据量才1000,于是乎果断采用了python

#!/usr/bin/env python
# coding=utf-8

n, l = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
tmp = a[0] - 0
for i in range(1, n):
    tmp = max(tmp, (a[i] - a[i - 1]) / 2.0)
tmp = max(tmp, l - a[n - 1])
print tmp

C题应当是贪心,因为我们最终是打算要平均数变大,那么最终往哪个数上加都是符合规则的。所以我们优先选择代价最小的那个。

/*************************************************************************
	> File Name: C.cc
	> Author: Severus
	> Mail: qinhuapeng425@gmail.com
	> Created Time: 2014年12月02日 星期二 00时46分46秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = (int)1e5 + 10;

typedef long long ll;

struct data {
    ll a, b;
    bool operator < (const data &rhs) const {
        return b < rhs.b;
    }
    void get() {cin >> a >> b;}
};

ll n, r, avg, sum;
data a[maxn];

int main() {
    cin >> n >> r >> avg;
    for (int i = 0; i < n; i++) {
        a[i].get();
        sum += a[i].a;
    }
    if (sum / n >= avg) {
        puts("0");
        return 0;
    }
    ll goal = n * avg;
    ll ans = 0;
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        ll tmp = goal - sum;
        if (a[i].a + tmp > r) {
            sum += (r - a[i].a);
            ans += (r - a[i].a) * a[i].b;
            a[i].a = r;
        } else {
            sum += tmp;
            ans += tmp * a[i].b;
            a[i].a += tmp;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

D题首先,一秒钟两个人一定打了 x+y 次,那么如果我们对一秒中的攻击排出来一个攻击次序来,这个非常可行,时间也就是 O(x+y) 的。那么不妨我们就排出来次序。假设有数组 atk atk[i] 表示一秒钟内第i次攻击是谁,1代表第一个人攻击,2代表第二个人攻击,0代表同时攻击,注意的是,如果是同时攻击我们需要连续存两次。然后我们只需要计算最后一秒需要攻击多少下就行了。

/*************************************************************************
	> File Name: D.cc
	> Author: Severus
	> Mail: qinhuapeng425@gmail.com
	> Created Time: 2014年12月02日 星期二 01时35分58秒
 ************************************************************************/

#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = (int)1e5 + 10;

int n;
ll x, y;
ll a[maxn];
vector<int> atk;

int main() {
    scanf("%d", &n);
    cin >> x >> y;
    ll tot = x * y;
    ll p = x, q = y;
    while (p <= tot && q <= tot) {
        while (p < q) {
            atk.push_back(2);
            p += x;
        }
        while (p > q) {
            atk.push_back(1);
            q += y;
        }
        if (p == q) {
            atk.push_back(0);
            atk.push_back(0);
            p += x; q += y;
        }
    }
    //cout << atk.size() << endl;
    for (int i = 0; i < n; i++) cin >> a[i];
    ll s = x + y;
    for (int i = 0; i < n; i++) {
        ll tmp = a[i] % s;
        if (atk[tmp - 1] == 1) puts("Vanya");
        else if (atk[tmp - 1] == 2) puts("Vova");
        else puts("Both");
    }
    return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值