Contest1814 - 2019年我能变强组队训练赛第七场
Posted accpted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Contest1814 - 2019年我能变强组队训练赛第七场相关的知识,希望对你有一定的参考价值。
Scores of Final Examination
On-Screen Keyboard
Tally Counters
Balance Scale
#pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; typedef long long ll; unordered_map<ll,bool> m1; int n,m,cnt; const int maxn=6e4; ll a[maxn],tot1,tot2,ans; ll w[105],b[105]; inline void dfs(int now,ll sum) if(now>n) m1[sum]=1; return; dfs(now+1,sum); dfs(now+1,sum+w[now]); dfs(now+1,sum-w[now]); inline ll read() ll res=0,f=1; char ch=getchar(); while (!isdigit(ch)) if (ch==‘-‘) f=-f; ch=getchar(); while (isdigit(ch)) res=(res<<3)+(res<<1)+ch-‘0‘; ch=getchar(); return f*res; int main() while (1) m=read();n=read(); if (n == 0 && m == 0) break; m1.clear(); cnt = tot1 = tot2 = 0; ans = 0x3f3f3f3f3f3f3f3f; for (int i = 1; i <= m; ++i) a[i]=read(); for (int i = 1; i <= n; ++i) w[i]=read(); dfs(1, 0); unordered_map<ll, bool>::iterator it; for (int i = 1; i <= m; ++i) if (m1[a[i]]) cnt++; else b[tot2++] = a[i]; m1.erase(a[i]); for (it = m1.begin(); it != m1.end(); ++it) a[tot1++] = it->first; if (cnt == m) printf("0\\n"); continue; for (int i = 0; i < tot1; ++i) cnt = 1; ll x = abs(a[i] - b[0]); for (int j = 1; j < tot2; ++j) if (m1.count(b[j] - x) || m1.count(b[j] + x)) cnt++; if (cnt == tot2) ans = min(ans, x); if (ans == 0x3f3f3f3f3f3f3f3f) printf("-1\\n"); else printf("%lld\\n", ans);
以上是关于Contest1814 - 2019年我能变强组队训练赛第七场的主要内容,如果未能解决你的问题,请参考以下文章
Contest1828 - 2019年我能变强组队训练赛热身赛
Contest1539 - 2019年我能变强组队训练赛第十一场
[ICPC训练联盟周赛1] CTU Open Contest 2019
快乐组队赛XD(2017 Chinese Multi-University Training, BeihangU Contest)
快乐组队赛XD(2017 Chinese Multi-University Training, BeihangU Contest)