AtCoder Beginner Contest 055题解
A.当a=1就把a改成14,b=1就把b改成14,然后比较a,b大小即可。
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int a, b;
int main()
{
cin >> a >> b;
if(a==1) a=14; if(b==1) b=14;
cout << ((a>b)?"Alice":((a==b)?"Draw":"Bob")) << endl;
} /*
比赛的时候的代码,狠智障地把题读错了。
但居然AC啦! 很迷啊~
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int NICO = 200000 + 10;
int a, b;
int main()
{
cin >> a >> b;
int ans;
if(a > b) ans = 1;
if(a < b) ans = 2;
if(a ==b) ans = 3;
if(a==1&&b==13)ans = 1;
if(a==13&&b==1)ans = 2;
if(ans == 1) cout << "Alice";
if(ans == 2) cout << "Bob";
if(ans == 3) cout << "Draw";
}
*/
B. 数据范围这么小~ 直接暴力,用4重循环check,岂不美哉!
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int NICO = 200000 + 10;
int n, m;
char s1[60][60],s2[60][60];
int main()
{
cin >> n >> m;
for(int i=0;i<n;i++) scanf("%s",s1[i]);
for(int i=0;i<m;i++) scanf("%s",s2[i]);
int ok = 0;
for(int i=0;i<=n-m;i++)
{
for(int j=0;j<=n-m;j++)
{
int ac = 1;
for(int a=i;a<i+m;a++)
{
for(int b=j;b<j+m;b++)
{
if(s1[a][b] != s2[a-i][b-j])
{
ac = 0;
}
}
}
if(ac) ok = 1;
}
}
cout << (ok?"Yes":"No") << endl;
}
C.数据范围比较小的TSP,继续暴力!
不过这个dfs写得真心难看!
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int NICO = 200000 + 10;
vector<int> vec[100];int n, m;
int res = 0, a[10];
void dfs(int used[], int x)
{
int ok = 1;used[x] = 1;
for(int i=1;i<=n;i++)
{
if(!used[i]) ok = 0;
}
if(ok) {res ++;return;}
for(int i=0;i<vec[x].size();i++)
{
int cur = vec[x][i];
if(used[cur]) continue;
int b[10];for(int j=1;j<=n;j++) b[j]=used[j];
dfs(b, cur);
}
}
int main()
{
cin >> n >> m;
for(int i=1;i<=m;i++)
{
int a, b;cin >> a >> b;
vec[a].push_back(b);
vec[b].push_back(a);
}
dfs(a, 1);
cout << res << endl;
}
D.活生生的一个背包, ans[i][j][k]: 表示使用前i个物品,凑成j克a物质,k克b物质最小耗费。
ans[i][j][k] = min (ans[i-1][j-a[i]][k-b[i]] + c[i], ans[i-1][j][k]);(初始化:ans[0][0][0]=0,其它为INF)
如果追求简洁の美感,可以把i省略掉,降一下ans数组的维度。
ps:降低维度的时候记得改变j, k的循环方向!喵!喵!喵!
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int INF = 10000007;
int ans[402][402];
int n, ma, mb;
int a[42],b[42],c[42];
int main()
{
for(int i=0;i<=400;i++)for(int j=0;j<=400;j++)ans[i][j] = INF;
ans[0][0] = 0;
cin >> n >> ma >> mb;
for(int i=1;i<=n;i++)
{
cin >> a[i] >> b[i] >> c[i];
}
for(int i=1;i<=n;i++)
{
for(int j=400;j>=a[i];j--)
{
for(int k=400;k>=b[i];k--)
{
ans[j][k] = min(ans[j][k], ans[j-a[i]][k-b[i]] + c[i]);
}
}
}
int res = INF;
int A = ma, B = mb;
while(A<=400&&B<=400)
{
res = min(res, ans[A][B]);
A += ma; B += mb;
}
if(res == INF) cout << -1 << endl;
else cout << res << endl;
}
AtCoder Beginner Contest 055题解的更多相关文章
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 151 题解报告
总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...
随机推荐
- Sql 知识点小结
使用数据库的好处: 1.安全 2.支持多用户操作 3.误删数据比较容易恢复 4.存储较大容量的数据MySql: MYsql AB公司开发的数据库, 现在归属Oracle公司,开元的关系型数据库RDBM ...
- [Kafka] - Kafka内核理解:Message
一个Kafka的Message由一个固定长度的header和一个变长的消息体body组成 header部分由一个字节的magic(文件格式)和四个字节的CRC32(用于判断body消息体是否正常)构成 ...
- A manager is becoming more and more popular in China
A manager is becoming more and more popular in China; many people want to possess a position like th ...
- GDKOI2015滚粗记
又是愉悦的滚粗了hahaha(特别不甘心啊啊啊) 其实去比赛每次都一样啦,就是每次吃饭睡觉补番考试评讲互黑跪烂什么的,这次就不用说了啦,先把老师要求写的东西贴出来再写点别的啦 这次暴露了很多问题,首先 ...
- NSRunLoop原理详解——不再有盲点
编程最怕的就是有盲点,不确定,而runloop官网对其提及的又很少:那么看完这篇应该使你有底气很多~ RunLoop整体介绍 An event-processing loop, during whic ...
- Two analytical 2d line intersection in OpenCASCADE
Two analytical 2d line intersection in OpenCASCADE eryar@163.com Abstract. OpenCASCADE geometric too ...
- 规范 : angular ui router path & params
在seo文章中提到url的path 必须是 why-us,而不是whyUS 所以定了规范,所有的path 必须why-us path ?后尾的是用来filter的,所以可以WhyUs 如果是不需要给s ...
- 2017-3-2 C#基础 结构体
1. 结构体:用户自定义类型定义位置:定义在Main函数的外面,类的里面 定义格式:struct 自定义名字{ public 数据类型 名字; public 数据类型 名字; ... ...} 声明实 ...
- 用Javascript大批量收集网站数据
最近为了写论文,要大批量收集慕课网的相关用户数据(因为用户个人主页是公开的),故而写了一个插件进行收集.需要在慕课网控制台输入.最后收集了3000多份数据. /* 收集项 收集标准 用户编号 慕课网用 ...
- Spark性能优化之道——解决Spark数据倾斜(Data Skew)的N种姿势
原创文章,同步首发自作者个人博客转载请务必在文章开头处注明出处. 摘要 本文结合实例详细阐明了Spark数据倾斜的几种场景以及对应的解决方案,包括避免数据源倾斜,调整并行度,使用自定义Partitio ...