比赛链接: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. Xamarin.Forms 5.0 来了

    Xamarin.Forms 5.0 已经正式发布,并带来其新功能,具体看官方博客https://devblogs.microsoft.com/xamarin/xamarin-forms-5-0-is- ...

  2. WebApi 中请求的 JSON 数据字段作为 POST 参数传入

    使用 POST 方式请求 JSON 数据到服务器 WebAPI 接口时需要将 JSON 格式封装成数据模型接收参数.即使参数较少,每个接口仍然需要单独创建模型接收.下面方法实现了将 JSON 参数中的 ...

  3. 基于Python的接口自动化-读写excel文件

    引言 使用python进行接口测试时常常需要接口用例测试数据.断言接口功能.验证接口响应状态等,如果大量的接口测试用例脚本都将接口测试用例数据写在脚本文件中,这样写出来整个接口测试用例脚本代码将看起来 ...

  4. FlatBuffers使用小结

    最近做一个Android APP,由于离线业务需求,需要在启动APP时候同步大量数据到APP上,遇到了JSON性能瓶颈.从下方的图片中可以看出,当使用 json 传输数据,在解析json的时候会产生大 ...

  5. MySQL where 条件字句查询

    where 条件字句 搜索条件可由一个或多个逻辑表达式组成 , 结果一般为布尔值 逻辑运算符 运算符 语法 描述 and && a and b a && b 逻辑与 两 ...

  6. 【ORA】ora-39700解决

  7. mysql—information_schema数据库

    一.介绍 MySQL中有一个默认数据库名为information_schema,在MySQL中我们把 information_schema 看作是一个数据库,确切说是信息数据库.其中保存着关于MySQ ...

  8. libnum报错问题解决

    之前在使用python libnum库时报错 附上报错内容 Traceback (most recent call last) : File" D:/python file/ctf/RSA共 ...

  9. bash shell数组使用总结

    本文为原创博文,转发请注明原创链接:https://www.cnblogs.com/dingbj/p/10090583.html  数组的概念就不多说了,大家都懂! shell数组分为索引数组和关联数 ...

  10. 入门OJ:Coin

    题目描述 你有n个硬币,第i硬币面值为ai,现在总队长想知道如果丢掉了某个硬币,剩下的硬币能组成多少种价值?(0价值不算) 输入格式 第一行一个整数n 第二行n个整数.,a1,a2-an. 1< ...