比赛链接:Here

1315A. Dead Pixel

签到题,

比较四个值

max(max(x, a - 1 - x) * b, a * max(y, b - 1 - y))

1315B. Homecoming

\(A\to B\) 花费 \(a\) 元

\(B\to A\) 花费 \(b\) 元

求要走到点 \(i\),从 \(i\) 上车能在 \(p\) 内到终点。


这个挺多解法的

  • 二分答案
  • 逆推模拟
  • DP

虚拟赛的时候写了DP

const int N = 1e6 + 10;
ll f[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int a, b, p; cin >> a >> b >> p;
string s; cin >> s;
int n = s.size();
if (s[n - 1] == 'A') f[n - 1] = a;
else f[n - 1] = b;
f[n] = 0;
ll pos = n - 1;
for (int i = n - 2; i >= 0; --i) {
if (i == n - 2) f[i] = (s[i] == 'A' ? a : b);
else if (s[i] == s[i + 1]) f[i] = f[i + 1];
else f[i] = f[i + 1] + (s[i] == 'A' ? a : b);
}
for (int i = 0; i < n; ++i)
if (f[i] <= p) {pos = i; break;}
cout << pos + 1 << "\n";
}
}

1315C. Restoring Permutation

题意:

给一组长度为 \(n\) 的 \(b[i]\) , 让你找一组长度为 \(2n\) 的 \(a[i]\) , 满足 \(b[i] = min(a[2*i-1 ] ,a[2*i])\) ,并且字典序最小 。


AtCoder 上做过类似的,直接考虑贪心

const int N = 1e4 + 10;
ll a[N], b[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n;
cin >> n;
map<ll, ll> mp;
for (int i = 1; i <= n; ++i) {
cin >> b[i], mp[b[i]] = 1;
}
bool f = 1;
for (int i = 1;f and i <= n; ++i) {
a[i * 2 - 1] = b[i];
ll k = b[i];
while (mp[k] == 1) k += 1;
if (k <= 2 * n) {
a[i * 2] = k;
mp[k] = 1;
} else f = 0;
}
if (!f) cout << "-1\n";
else
for (int i = 1; i <= 2 * n; ++i)cout << a[i] << " \n"[i == 2 * n];
}
}

1315D. Recommendations

题意:

你有 \(n\) 本书,每本书的数量为 \(a[i]\) ,你可以花费 \(t[i]\) 让这对应的书加 \(1\) ,求总花费最小并使得 \(a[i]\) 各不相同。

利用容器 multiset

每次把同样数量的书放入一个 multiset 里,然后把最大的书拿出来保留,其他的书花费的时间加到答案里,再把 +1 之后书放进去,再反复操作。

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i) cin >> v[i].first;
for (int i = 0; i < n; ++i) cin >> v[i].second;
multiset<int>ms;
sort(v.begin(), v.end());
int c = 1, i = 0;
ll s = 0, r = 0;
while (1) {
if (ms.size() == 0 && i == n) {
cout << r;
return 0;
}
if (ms.size() == 0) c = v[i].first;
for (; i < n && v[i].first == c; ++i) {
ms.insert(-v[i].second);
s += v[i].second;
}
s += *ms.begin();
ms.erase(ms.begin());
r += s, c++;
}
}

Codeforces Round #623 (Div. 2) A~D题,D题multiset使用的更多相关文章

  1. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  4. Codeforces Round #303 (Div. 2) D. Queue 傻逼题

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

  5. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  6. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  7. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  8. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  9. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  10. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

随机推荐

  1. Windows_Cmd常用操作配置

    目录 特定功能执行命令 显示系统当前版本 电源管理 历史命令相关 显示路由表 显示本地 ARP 缓存 测试主机 联通性 查看网卡信息 修改DOS窗口中的编码格式 诊断域名系统 (DNS) 基础结构的信 ...

  2. 使用Tensorrt部署,C++ API yolov7_pose模型

    使用Tensorrt部署,C++ API yolov7_pose模型 虽然标题叫部署yolov7_pose模型,但是接下来的教程可以使用Tensorrt部署任何pytorch模型. 仓库地址:http ...

  3. weblogic端口号和内存怎么修改?

    在WebLogic中修改端口号和内存分配是一项重要的任务,它涉及到服务器性能和应用程序的可靠性.下面我将详细介绍如何修改WebLogic的端口号和内存设置. 修改端口号 WebLogic使用多个端口来 ...

  4. 汇报工作与众不同:在PPT中展示Datainside动态图表

    题目要求了解在PPT中展示Datainside动态图表,下面是关于该主题的详细介绍. 内容可视化:概念与定义 内容可视化(Data Visualization)是将数据以图形或其他视觉形式呈现的过程, ...

  5. [ABC238G] Cubic?

    Problem Statement Given a sequence $A$ of $N$ numbers, answer the following $Q$ questions. In the $i ...

  6. K8s 里如何优雅地使用 /dev/shm 实现容器间共享内存

    目录 1. 从 docker run 的 --shm-size 参数聊起 2. Linux 里的 /dev/shm 3. Docker 对共享内存的支持 4. K8s 里如何设置 /dev/shm 大 ...

  7. Odoo16—权限控制

    odoo的权限控制是通过用户组来实现的,在用户组中配置控制权限,然后再添加用户到用户组中,从而实现对用户的访问和操作权限控制.一个用户可以属于多个用户组,用户最终的权限范围取决于所属用户组权限的并集. ...

  8. 华企盾DSC导致Solidworks无法导出xls文件

    将Solidworks进程和Excel进程的OLE控制和启用虚拟重定向都关闭

  9. 如何实现CesiumJS的视效升级?

    CesiumJS作为一款强大的地理可视化引擎,为我们提供了丰富的地球数据可视化和交互展示的能力.然而,随着用户需求的不断增加和技术的不断进步,如何进一步提升CesiumJS的视觉效果成为了一个重要的问 ...

  10. Wifi BSSID获取

    代码很简单,通过wifiManager 获取wifiinfo,从而获取bssid, public static String getWifiSSID(Context context) { String ...