Opencup XII, Grand Prix of Tokyo F.Robots
Posted tiany7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencup XII, Grand Prix of Tokyo F.Robots相关的知识,希望对你有一定的参考价值。
F.Robots
来复健,但是没料到是GP场,就不该来,应该去vp
这道题的题意是给两个数组a和b,对于每个b,会有最近的依然active的a来配对,问最小的距离是多少,并且给出一种删b的方案
样例给了:
3
1 2 3
11 12 13
答案是30,我们先删掉13,然后删掉12,最后删掉11, 为什么不从前往后呢?
因为我们没法保证所有的a[i] <> b[i],会出现一种情况,当前的b抢走了前面的a,或者前面的b抢走了当前的a,为了保证一致性,我们可以分类讨论
我们固定a[i] < b[i] 为唯一的ordering,那么在我们新iterate到的节点,我们看看这个节点的a[i]会不会被前面抢走,如果会的话,先把前面爆了,然后再塞入当前的b,这样就保证了一致性,如果不会被爆,那么我们就把第i个节点爆了,从而保证无后效性。
那么怎么维护呢?我们可以用一个栈来维护。
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
constexpr int limit = (4e5 + 5);//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-9
#define FASTIO ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#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;
int a[limit];
int b[limit];
bitset<limit>vis;
struct node
int i, aa, bb;
;
list<node>rp;
void solve()
cin>>n;
rep(i,1,n)cin>>a[i];
rep(i,1,n)cin>>b[i];
ll ans = 0;
vector<int>res;
rep(i,1, n)
if(a[i] < b[i])
rp.push_back(int(i), a[i], b[i]);
else if(a[i] == b[i])
res.push_back(i);
else
if(rp.size() and llabs(rp.back().bb - rp.back().aa) < llabs(rp.back().bb - a[i]))
while(rp.size() and llabs(rp.back().bb - rp.back().aa) < llabs(rp.back().bb - a[i]))
res.push_back(rp.back().i);
rp.pop_back();
rp.push_back(int(i), a[i], b[i]);
else
res.push_back(i);
for(auto &i : rp| views::reverse)
res.push_back(i.i);
for(auto &i : res)
ans += llabs(a[i] - b[i]);
cout<<ans<<endl;
for(auto &i : res )cout<<i<<" ";
cout<<endl;
;
int32_t main()
#ifdef LOCAL
FOPEN;
// FOUT;
#endif
FASTIO
// int kase;
// cin>>kase;
// while (kase--)
invoke(solve);
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s";
return 0;
2015-2016 XVI Open Cup, Grand Prix of Bashkortostan, SKB Kontur Cup Stage 2
Rank | Solved | A | B | C | D | E | F | G | H | I | J | K | L | M |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
72/213 | 8/13 | O | . | O | O | . | O | . | O | O | O | . | O | . |
O
: 当场通过
?
: 赛后通过
.
: 尚未通过
A Abstract Picture
solved by chelly
chelly‘s solution
B Battle Mage
unsolved
C Constant Ratio
solved by chelly
chelly‘s solution
D dir -C
solved by chelly
chelly‘s solution
E Extreme Permutations
unsolved
F Find the Length
solved by chelly
chelly‘s solution
G Game ``Minesweeper‘‘
unsolved
H Hierarchy
solved by chelly
chelly‘s solution
I Interactive Casino
solved by chelly
chelly‘s solution
J Judgement
solved by chelly
chelly‘s solution
K Krotek
unsolved
L Liesbeth and the String
solved by ch&chelly
chelly‘s solution
M Matrix, The
unsolved
Dirt Replay
以上是关于Opencup XII, Grand Prix of Tokyo F.Robots的主要内容,如果未能解决你的问题,请参考以下文章
XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Peterhof.
2019-2020 XX Open Cup, Grand Prix of Korea
XX Open Cup, Grand Prix of Tokyo
[XXI Open Cup.Grand Prix of Korea]Advertisement Matching