比赛链接:https://atcoder.jp/contests/abc173/tasks

A - Payment

题意

计算只用 $1000$ 元支付某个价格 $n$ 的找零是多少。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
cout << (1000 - n % 1000) % 1000 << "\n";
}

B - Judge Status Summary

题意

给出 $n$ 个不外乎为 "AC", "WA", "TLE", "RE" 的字符串,统计四个字符串的个数。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
map<string, int> mp;
for (int i = 0; i < n; i++) {
string s; cin >> s;
++mp[s];
}
for (auto s : {"AC", "WA", "TLE", "RE"})
cout << s << " x " << mp[s] << "\n";
}

C - H and V

题意

给出一个 $h \times w$ 的黑白方阵,可以选择将一些行和列涂红,问使得方阵中刚好有 $k$ 个黑方块的方案个数。

题解一

$dfs$ 枚举所有情况。

代码

#include <bits/stdc++.h>
using namespace std;
const int N = 10; int h, w, k, ans;
char C[N][N];
bool choose_row[N];
bool choose_col[N]; void dfs(int row, int col) {
if (row <= h) {
choose_row[row] = true;
dfs(row + 1, col);
choose_row[row] = false;
dfs(row + 1, col);
} else if (col <= w) {
choose_col[col] = true;
dfs(row, col + 1);
choose_col[col] = false;
dfs(row, col + 1);
} else {
char MP[N][N] = {};
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
MP[i][j] = C[i][j];
for (int i = 1; i <= h; i++)
if (choose_row[i])
for (int j = 1; j <= w; j++)
MP[i][j] = '.';
for (int i = 1; i <= w; i++)
if (choose_col[i])
for (int j = 1; j <= h; j++)
MP[j][i] = '.';
int cnt = 0;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
if (MP[i][j] == '#')
++cnt;
if (cnt == k) ++ans;
}
} int main() {
cin >> h >> w >> k;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
cin >> C[i][j];
dfs(1, 1);
cout << ans << "\n";
}

题解二

将每行或列的选取状态压缩为二进制的 $0$ 或 $1$,枚举行和列的所有状态,每次只考虑未涂的行和列的方块。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, k; cin >> h >> w >> k;
char MP[h][w] = {};
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> MP[i][j];
int ans = 0;
for (int maskR = 0; maskR < (1 << h); maskR++) {
for (int maskC = 0; maskC < (1 << w); maskC++) {
int cnt = 0;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (!((maskR >> i) & 1) and !((maskC >> j) & 1) and MP[i][j] == '#')
++cnt;
if (cnt == k) ++ans;
}
}
cout << ans << "\n";
}

D - Chat in a Circle

题意

可以将 $n$ 个数按照任意顺序插进一个空圈中,每次插入一个数的收益为相邻数的最小值,问最大收益为多少。

题解

先用较大的一半数构成一个圈,然后将剩下较小的一半数插入两个较大的数之间,注意最后插入的较小数的收益与 $n$ 的奇偶性有关。

代码

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n; cin >> n;
int a[n] = {};
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n, greater<int>());
ll ans = 0;
int half = (n + 1) / 2;
ans += accumulate(a, a + half - 1, 0LL);
ans += accumulate(a + 1, a + 1 + n - half, 0LL);
if (n % 2 == 0)
ans -= a[half], ans += a[half - 1];
cout << ans << "\n";
}

AtCoder Beginner Contest 173的更多相关文章

  1. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  2. AtCoder Beginner Contest 173 E Multiplication 4 分类讨论 贪心

    LINK:Multiplication 4 害怕别人不知道我有多菜 那就上张图: 赛时 太慌了 (急着AK 题目不难却暴露我的本性 根本不思考无脑写 wa了还一直停不下来的debug 至少被我发现了1 ...

  3. AtCoder Beginner Contest 173 E - Multiplication 4 (思维)

    题意:有\(n\)个数,从中选\(k\)个数累乘,求最大的乘积\((mod\ 10^9+7)\). 题解: 1.假如全是负数,并且选奇数个,那么从小到大选. 2.否则,考虑当前状态,假如\(k\)是奇 ...

  4. AtCoder Beginner Contest 173 D - Chat in a Circle (贪心)

    题意:有一个空环和\(n\)个点,每次可以选择一个点放在空环上,并且获得周围两个点中最小的那个的权值,问能获得的最大的权值是多少? 题解:我们每次都优先放最大的进去,注意每次放的时候都要将这个点放在当 ...

  5. AtCoder Beginner Contest 173 C - H and V (二进制枚举)

    题意:有一张图,.表示白色,#表示黑色,每次可以将多行和多列涂成红色(也可不涂),问有多少种方案,使得剩下黑点的个数为\(k\). 题解:又学到了新的算法qwq,因为这题的数据范围很小,所以可以用二进 ...

  6. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  7. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  8. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  9. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

随机推荐

  1. shelll中test命令的使用【转】

    Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 数值测试 参数 说明 -eq 等于则为真 -ne 不等于则为真 -gt 大于则为真 -ge 大于等于 ...

  2. 十四:SQL注入之类型及提交注入

    简要明确参数类型 数字,字符,搜索,json等 简要明确请求方法 GET,POST,COOKIE,REQUEST,HTTP头 其中SQL语句干扰符号:' " % ) } 等,具体查看用法 非 ...

  3. 计算起始车站车费问题-JavaScript数组对象写法

    计算起始站车费 题目:深圳--60--广州--50-虎门--40- -中山--36-珠海一34-澳门一89一香港以上车票费用计算,如坐车深圳到广州60元,广州到虎门50元,深圳到虎门就是60+50-1 ...

  4. 【Oracle】查看oracle表空间大小及增加表空间的几种方法

    在oracle中表空间是必不可少的.但是怎么查看表空间呢 简单的查看方式是: SQL> select tablespace_name from dba_tablespaces; 想要查看表空间对 ...

  5. Python3.9的http.client.py下的HTTPMessage类中的方法getallmatchingheaders的bug修复建议

    在官方网站已经提交相关issue,不过目前看好像还没有修复.具体的bug位置为: http文件夹下的client.py文件,代码位置为:类HTTPMessage下的方法getallmatchinghe ...

  6. SDNU_ACM_ICPC_2021_Winter_Practice_1st [个人赛] 2021.1.19 星期二

    SDNU_ACM_ICPC_2021_Winter_Practice_1st [个人赛] K - Color the ball 题意: 有n个气球,每次都给定两个整数a,b,给a到b内所有的气球涂一个 ...

  7. uni-app开发经验分享九: 组件传值

    一.父组件向子组件传值 通过props来实现,子组件通过props来接收父组件传过来的值! 1.逻辑梳理 父组件中: 第一步:引入子组件: import sonShow from '../../com ...

  8. 让源码包apache服务被服务管理命令识别

    在默认情况下,源码包服务是不能被系统的服务管理命令所识别和管理的,但是如果我们做一些设定,则也是可以让源码包服务被系统的服务管理命令所识别和管理的.不过笔者并不推荐大家这样做, 因为这会让本来区别很明 ...

  9. 使用Jmeter对SHA1加密接口进行性能测试

    性能测试过程中,有时候会遇到需要对信息头进行加密鉴权,下面我就来介绍如何针对SHA1加密鉴权开发性能测试脚本1.首先了解原理,就是需要对如下三个参数进行SHA1加密,(AppSecret + Nonc ...

  10. Java并发包源码学习系列:阻塞队列实现之PriorityBlockingQueue源码解析

    目录 PriorityBlockingQueue概述 类图结构及重要字段 什么是二叉堆 堆的基本操作 向上调整void up(int u) 向下调整void down(int u) 构造器 扩容方法t ...