Codeforces Round #610 (Div. 2) 题解

  • Temporarily unavailable
  • K for the Price of One (Hard Version)
  • Petya and Exam

Temporarily unavailable

\[
Time Limit: 1 s\quad Memory Limit: 256 MB
\]
直接计算出 \([c-r, c+r]\) 在 \([a, b]\) 中的范围有多大,然后减掉就可以了。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

int main() {
    scanf("%d", &T);
    while(T--) {
        ll a, b, c, r, ans;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &r);
        if(a>b) swap(a, b);
        ans = b-a;
        ll over = max(a, min(c+r, b)) - min(b, max(c-r, a));
        printf("%lld\n", ans-over);
    }
    return 0;
}

K for the Price of One (Hard Version)

\[
Time Limit: 2 s\quad Memory Limit: 256 MB
\]
首先肯定是买最便宜的,由于有 \(k\) 个只能买 \(k\) 个,所以可以看成有两种策略,买 \(1\) 个和买 \(k\) 个,然后用 \(dp[i]\) 表示买了前 \(i\) 个物品的最少花费,然后看给出的钱可以买多少个。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m, k;
int cas, tol, T;

ll dp[maxn];
int a[maxn];

int main() {
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d%d", &n, &m, &k);
        for(int i=1; i<=n; i++) scanf("%d", &a[i]);
        for(int i=1; i<=n; i++) dp[i] = INF;
        dp[0] = 0;
        sort(a+1, a+1+n);
        for(int i=1; i<=n; i++) {
            if(i-k>=0)
                dp[i] = min(dp[i-1], dp[i-k])+a[i];
            else
                dp[i] = dp[i-1]+a[i];
        }
        ll ans = 0;
        for(int i=n; i>=1; i--) {
            if(dp[i] <= m) {
                ans = i;
                break;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Petya and Exam

\[
Time Limit: 2 s\quad Memory Limit: 256 MB
\]
由于有一个限制时间 \(t_i\),那么我可以按限制时间 \(t_i\) 排序来完成每一个作业。

令 \(p[i]\) 表示完成 \(i\) 个作业需要的时间,那么我想要完成这 \(i\) 个作业,我所用的时间必须在 \(t_{i+1}\) 以内,这些是必须要完成的作业。

接下来还有一部分剩下的时间,我可以用这些剩余的时间去贪心完成还没到达限制时间的作业,每次先完成简单的,在完成难的。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

ll n, m;
int cas, tol, T;

struct Node {
    ll a, b, p;
    bool operator < (Node c) const {
        return b<c.b;
    }
} node[maxn];
ll p[maxn], a[2];

ll solve(ll time, ll x, ll y) {
    ll cnt = 0;
    ll oka = min(x, time/a[0]);
    cnt += oka;
    time -= oka*a[0];
    ll okb = min(y, time/a[1]);
    cnt += okb;
    return cnt;
}

int main() {
    scanf("%d", &T);
    while(T--) {
        scanf("%lld%lld%lld%lld", &n, &m, &a[0], &a[1]);
        for(int i=1, x; i<=n; i++) {
            scanf("%lld", &node[i].p);
            node[i].a = a[node[i].p];
        }
        for(int i=1; i<=n; i++) {
            scanf("%lld", &node[i].b);
        }
        p[0] = 0;
        sort(node+1, node+1+n);
        node[n+1].b = m+1;
        for(int i=1; i<=n; i++) p[i] = p[i-1]+node[i].a;
        ll ans = 0, cnt[2] = {0};
//      for(int i=1; i<=n; i++) printf("%d%c", node[i].a, i==n ? '\n':' ');
//      for(int i=1; i<=n; i++) printf("%d%c", node[i].b, i==n ? '\n':' ');
//      for(int i=1; i<=n; i++) printf("%d%c", p[i], i==n ? '\n':' ');
//      cout << "=====" << endl;
        for(int i=n; i>=0; i--) {
            if(p[i] < node[i+1].b)
                ans = max(ans, i+solve(node[i+1].b-p[i]-1, cnt[0], cnt[1]));
            cnt[node[i].p]++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Jiaaaaaaaqi/p/12099360.html

时间: 2024-11-07 15:50:47

Codeforces Round #610 (Div. 2) 题解的相关文章

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

Codeforces Round #177 (Div. 2) 题解

[前言]咦?现在怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2.至于怎么决定场次嘛,一般我报一个数字A,随便再拉一个人选一个数字B.然后开始做第A^B场.如果觉得机密性不高,来点取模吧.然后今天做的这场少有的AK了.(其实模拟赛只做完了4题,最后1题来不及打了) 等等,话说前面几题不用写题解了?算了,让我难得风光一下啦. [A] A. Polo the Penguin and Segments time limit per test 2 seconds mem

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #561 (Div. 2) 题解

Codeforces Round #561 (Div. 2) 题解 题目链接 A. Silent Classroom 水题. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105; int n; char s[N], t[N]; int main() { cin >> n; for(int i = 1; i <= n; i++) { scanf(&q

Codeforces Round #608 (Div. 2) 题解

目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 程序 D. Portals 题意 做法 程序 E. Common Number 题意 做法 程序 结束语 Codeforces Round #608 (Div. 2) 题解 前言 题目链接:仅仅只是为了方便以题目作为关键字能查找到我的题解而已(逃 Codeforces 1271A Codeforce

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(