Codeforces Round #610 (Div. 2) a/b/c

题目

传送门



A Temporarily unavailable   standard input/output 1 s, 256 MB 

  给一个线段ab, 问除去 c点圆心半径r覆盖的 线段多长,如果圆在线段外 直接输出 ab 长度就行, 若在线段内 则输出cout << max(b-a-max((min(c+r,b)-max(a,c-r)),0), 0) ,迷糊的话纸上画下大概就能明白。
B1 K for the Price of One (Easy Version) , B2 K for the Price of One (Hard Version)       standard input/output 2 s, 256 MB 

  B1 k = 2, B2   k <= n,  n <= 2e5   ai<=2e9
  You must buy **exactly** k gifts to use the offer.   可以推出贪心求得值为最优解,

  for  i 0~n

  当 i >=k 时,可以直接付a[i] 的钱买下  i-k ~ i 号货物,

  当   i <k-1 且 i > 0 , 不足k 所以不能享受折扣  需要付a[0]+....+a[i] 的钱才能买下 0 ~ i 号货物, 所以需要求个前缀和, 至于为什么边界是k-1 是因为数组下标0 和 1的故事

C Petya and Exam    standard input/output 2 s, 256 MB 

  额, 想到了贪心, 但是没贪对, 首先给你多组数据, 每组数据给你 n t a b, 问最多能解决的问题, 其中每道题分为难易 且 有变成mandatory(必须要解决 ddl) 的时间, 所以可以先用个pair 存储下每道题的难易 和 时间, 再根据每道题的 ddl 从小到大 排个序, 然后可以证明当 ti-1 时间走 是最优的(因为如果再晚的话 就要面对第 i 道题, 更早的话 没有必要) 而 ti-1 时间可以 必须把第 i 道题目之前的所有题目做完(因为都到了 ddl) 然后把剩下的时间贪心地先做剩下题目中的简单题  时间有多余的话再做剩下题目中的难题,然后对每个题目 取 之前已经到ddl的题目数和贪心数 的最大值, 有个小细节是需要在数组最后面加一个 t+1,0  因为最迟离开时间是 t , 代码如下

#include<bits/stdc++.h>//Codeforces Round #608 (Div. 2)
using namespace std;

#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
#define _per(i,a,b) for(int i = (a); i > (b); i--)
#define ll long long
void taskA(){
    int t;
    cin >> t;
    while(t--) {
        int a,b,c,r; cin >> a >> b >> c >> r;
        if(a > b) swap(a, b);
        if(c-r >= b || c+r <= a) cout << b-a << ‘\n‘;
        else//(c <= b)
            cout << max(b-a-max((min(c+r,b)-max(a,c-r)),0), 0) << ‘\n‘;
        //else if(c-r <= b) cout << max(a-b-(min(c+r,b)-max(a,c-r)), 0) << ‘\n‘;
          //  cout <<
    }
    return;
}
void taskB(){
    int t; cin >> t;
    while(t--) {
        int n,p,k; cin >> n >> p >> k;
        vector<int> a(n, 0);
        _for(i,0,n) cin >> a[i];

        int ans = 0;
        sort(a.begin(), a.end());
        _for(i,0,n) {
            if(i >= k) a[i] += a[i-k];
            //else if(i && i != k-1) a[i] += a[i-1];
            else if(i < k-1 && i) a[i] += a[i-1];

            if(a[i] <= p) ans = i+1;
//cout << " i = " << i;
//cout << "\tans = " << ans << " a[i]= " << a[i] << "\n";
        }cout << ans << "\n";
    }return;
}
void taskC(){
    int t1; cin >> t1;
    while(t1--){
        ll n,t,a,b; cin >> n >> t >> a >> b;
        vector<pair<ll, ll> > dif(n);
        ll ans = 0, cnta = 0, cntb = 0;
        _for(i,0,n) {
            cin >> dif[i].second;
            dif[i].second ? cntb++ : cnta++;
        }
        _for(i,0,n) cin >> dif[i].first;
        dif.push_back({t+1, 0});//  t 时间 离去
        sort(dif.begin(), dif.end());

        ll cnt1 = 0, cnt2 = 0;
        _rep(i,0,n) {
            ll need = a*cnt1+cnt2*b;
            ll has = dif[i].first-1-need;
            if(has >= 0) {
                ll cana = min(cnta-cnt1, has/a);
                has -= a*cana;
                ll canb = min(cntb-cnt2, has/b);
                ans = max(ans, cnt1+cnt2+cana+canb);
            }
            int l = i;
            while(l < dif.size() && dif[i].first == dif[l].first) {
                if(dif[l].second) cnt2++;//记录同一个ddl 有几个任务, 这些都需要完成
                else cnt1++;
                l++;
            }
            i = l - 1;
        } cout << ans << ‘\n‘;
    } return;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    //taskA();
    //taskB();   //taskC();
    return 0;
}
taskB();

原文地址:https://www.cnblogs.com/163467wyj/p/12112911.html

时间: 2024-08-02 12:05:29

Codeforces Round #610 (Div. 2) a/b/c的相关文章

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> #includ

Codeforces Round #610 (Div. 2)

比赛链接 A 求两条线段交的长度. \({\frak{code:}}\) #include<bits/stdc++.h> #define IL inline #define LL long long using namespace std; const int N=3e3+5,p=998244353; int a,b,c,r; IL int in(){ char c;int f=1; while((c=getchar())<'0'||c>'9') if(c=='-') f=-1;

Codeforces Round #610 (Div. 2)E(模拟,DFS)

先找到一条多边形的边,然后循环一圈输出多边形上的点.把每个三角形看作一个结点,以两个三角形之间公用边为边建立一张图,DFS输出叶子结点,则得到先切后切的顺序. 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 vector<int>v[100007]; 5 bool vis[100007]; 6 void dfs(int x){ 7 vis[x]=1; 8 for(au

【排序】【规律】Codeforces Round #254 (Div. 2) - D. Rooter&#39;s Song

D. DZY Loves FFT Source http://codeforces.com/contest/445/problem/D Description Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w?×?h, represented by a re

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除