codeforces div2 1684D. Traps(贪心排序)
作者:互联网
这个题好像也没有什么好说的,就是一个数列,包含一些陷阱,造成的伤害是那个位置上的数字,你有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