ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

codeforces div2 1684D. Traps(贪心排序)

2022-07-10 12:32:20  阅读:198  来源: 互联网

标签:Traps int rhs codeforces long cin 1684D 伤害 define


这个题好像也没有什么好说的,就是一个数列,包含一些陷阱,造成的伤害是那个位置上的数字,你有k次可以跳过去的机会,但跳完之后后面的陷阱伤害就会+1

一开始很好像,我们可以总结一下每个跳过操作对后面造成的影响,首先减去的伤害是a[i], 但是又会增加n - i点其他伤害,所以就按照实际减去的伤害排序就好了

只不过我感觉这个题有hack点,因为你如果你在i点跳过了,有一个j点,i < j, 这个时候造成的伤害是没法通过贪心排序计算进去的,但还是ac了,很奇怪

1700的题,还行,今天把akuna的笔试做掉好了

#include <bits/stdc++.h>
using namespace std;
#define limit (1000000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-9
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a, b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\akioi\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\akioi\\dabiao.txt", "wt", stdout)
typedef long long ll;
typedef unsigned long long ull;
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;

inline ll read() {
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    ll sign = 1, x = 0;
    char s = getchar();
    while (s > '9' || s < '0') {
        if (s == '-')sign = -1;
        s = getchar();
    }
    while (s >= '0' && s <= '9') {
        x = (x << 3) + (x << 1) + s - '0';
        s = getchar();
    }
    return x * sign;
#undef getchar
}//快读
void print(ll x) {
    if (x / 10) print(x / 10);
    *O++ = x % 10 + '0';
}

void write(ll x, char c = 't') {
    if (x < 0)putchar('-'), x = -x;
    print(x);
    if (!isalpha(c))*O++ = c;
    fwrite(obuf, O - obuf, 1, stdout);
    O = obuf;
}


int n, m, k;
int a[limit];
struct node{
    int dmg, left, idx;//能减掉的伤害 + 增加的伤害
    bool operator<(const node &rhs)const{
        if(dmg - left  != rhs.dmg - rhs.left)
            return dmg - left > rhs.dmg - rhs.left;
        return idx < rhs.idx;
    }
}p[limit];
void solve() {
    cin>>n>>k;
    rep(i,1,n){
        cin>>a[i];
        p[i] = {a[i], int(n - i), int(i)};
    }
    if(n == k){
        cout<<0<<endl;
        return;
    }
    sort(p + 1, p + 1 + n);
    ll ans = 0;
    rep(i,1,k){
        a[p[i].idx] = -1;
    }
    int tot = 0;
    per(i,1,n){
        if(a[i] == -1){
            ans += n - i - tot;
            ++tot;
        }else{
            ans += a[i];
        }
    }
    cout<<ans<<endl;

}
int32_t main() {
#ifdef LOCAL
    FOPEN;
//    FOUT;
#endif
    FASTIO

    int kase;
    cin >> kase;
    while (kase--)
        solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}

 

标签:Traps,int,rhs,codeforces,long,cin,1684D,伤害,define
来源: https://www.cnblogs.com/tiany7/p/16462961.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有