AtCoder Beginner Contest 118 解题报告
A - B +/- A
#include <bits/stdc++.h>
int main() {
int a, b; std::cin >> a >> b;
b % a ? std::cout << b - a : std::cout << a + b;
}
B - Foods Loved by Everyone
#include <bits/stdc++.h>
int cnt[31], ans;
int main() {
int n, m; std::cin >> n >> m;
for(int i = 1; i <= n; ++i) {
int k, x; std::cin >> k;
while(k--) std::cin >> x, ++cnt[x];
}
for(int i = 1; i <= m; ++i) if(cnt[i] == n) ++ans;
std::cout << ans << std::endl;
}
C - Monsters Battle Royale
答案即为所有数的\(\gcd\)。
考虑\(\gcd(n,n-x)=\gcd(n,x)\)。
实际上每次减法就是在重复这个过程。
#include <bits/stdc++.h>
int main() {
int n, a, x; std::cin >> n >> a; --n;
while(n--) std::cin >> x, a = std::__gcd(a, x);
printf("%d\n",a);
}
D - Match Matching
设\(f[i]\)表示用了\(i\)根火柴,能拼出的数的个数,输出答案对每个dp值维护一个vector即可。
\]
每次转移都将原数组的vector也转过去,push个a[j]进去即可。
注意排序,按数字大小倒序排序,最后倒序输出出去。
复杂度\(O(nmlen+mlogm)\),因为是dp,所以这个len随机数据下实际不会跑很满,总时间才用了104ms
#include <bits/stdc++.h>
const int N = 10010;
const int s[10] = {0,2,5,5,4,5,6,3,7,6};
struct Node {int id, cnt;} a[20];
int f[N], n, m;
std::vector<int>v[N];
bool operator < (Node a, Node b) { return a.id > b.id; }
int main() {
std::cin >> n >> m;
for(int i = 1; i <= m; ++i) std::cin >> a[i].id, a[i].cnt = s[a[i].id];
std::sort(a + 1, a + m + 1); std::memset(f, -0x3f, sizeof(f)); f[0] = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
if(i - a[j].cnt >= 0 && f[i - a[j].cnt] + 1 > f[i])
v[i] = v[i - a[j].cnt], v[i].push_back(a[j].id), f[i] = f[i - a[j].cnt] + 1;
for(int i = v[n].size() - 1; i >= 0; --i) std::cout << v[n][i];
}
AtCoder Beginner Contest 118 解题报告的更多相关文章
- AtCoder Beginner Contest 122 解题报告
手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...
- AtCoder Beginner Contest 146解题报告
题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...
- Atcoder Beginner Contest 124 解题报告
心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...
- AtCoder Beginner Contest 120 解题报告
为啥最近都没有arc啊... A - Favorite Sound #include <algorithm> #include <iostream> #include < ...
- AtCoder Beginner Contest 117 解题报告
果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 129 解题报告
传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...
- AtCoder Beginner Contest 127 解题报告
传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...
- AtCoder Beginner Contest 126 解题报告
突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...
随机推荐
- PAT A1144 The Missing Number (20 分)——set
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- #ifdef __cplusplus extern "C" { #endif”的定义
平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #e ...
- 【Codeforces 152E】Garden
Codeforces 152 E 题意:给你一个\(n\times m\)的格子,每个格子里面有一个值\(a_{i,j}\)表示如果要将这个格子变成路的话需要花费这么多代价.现在有\(k\)个特殊格子 ...
- Android学习之基础知识五—RecyclerView(滚动控件)
RecyclerView可以说是增强版的ListView,不仅具有ListVIew的效果,还弥补许多ListView的不足. 一.RecyclerView的基本用法 与百分比布局类似,Recycler ...
- Web —— 在自己电脑搭建网站,发布到公网,并使用域名访问
导读 闲置着一台笔记本,想拿来作为服务器来玩,先拿来发布之前的毕业设计的博客系统,百度搜出的资料玉石难辨,而且大多数前篇一律,刚开始参考了大多数资料来设置还是没能真正发布成功,最后发现原来网上大部分提 ...
- 关于TCP和MQTT之间的转换
现在物联网流行的就是MQTT 其实MQTT就是在TCP的基础上建立了一套协议 可以看这个,本来我自己想用Wireshark监听一下,不过百度一搜索一大把,我就不测试了 https://blog.csd ...
- ADO.NET分享
看到<c#从入门到精通(第三版)>书中对ado.net里几种方法打的比方,很有意思就发一下. 1)这张图中,把数据比作水,储存了大量数据. 2)Connection对象好像进水龙头,插在水 ...
- c语言程序设计 第一例子
#include <studio.h> int main(){ printf("this is dog.\n"); return 0; } studio.h 表示st ...
- Ionic 图片延时加载
图片的延时加载是为了提供App的运行效率,那么是如何实现的呢?献上github: https://github.com/paveisistemas/ionic-image-lazy-load 1.下 ...
- 仓储层接口IBaseRepository解析
//代码调用由业务层调用,调用方式详见源代码的业务层,升级直接替换TT模板即可,无需覆盖系统using System; using System.Collections.Generic; using ...