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/ ...
随机推荐
- Raspberry树莓派学习笔记1—基本介绍
树莓派的简单介绍 一个名片大小的迷你个人电脑主机,还有wifi/蓝牙... 运行完整的Linux操作系统(注意关键字:完整,不是精简过的嵌入式Linux) 开源的硬件平台.与普通主机不同的是,它带有简 ...
- Javascript—②函数
新手Perfect教程之Javascript②教程-函数 前言:上回我们是从hello world开始的,本期将会讲"函数" 在学自定义函数之前,先了解几个已经定义好的函数: 1 ...
- Python thread local
由于GIL的原因,笔者在日常开发中几乎没有用到python的多线程.如果需要并发,一般使用多进程,对于IO Bound这种情况,使用协程也是不错的注意.但是在python很多的网络库中,都支持多线程, ...
- 华硕ASUS笔记本 中间5个指示灯分别表示什么
1.图案像个灯的叫电源状态指示灯:当笔记本电脑启动时,电源状态指示灯便会亮起来并会在笔记本电脑进入休眠模式(Sleep Mode,Suspend-to-RAM)时缓慢闪烁.当笔记本电脑关机或进入休眠模 ...
- HttpHelper万能框架V1.6
下载地址:http://yun.baidu.com/share/link?uk=1745303310&shareid=1343567367 引入:System.Web和System.Web.E ...
- HttpRequest获取文件流,HttpResponse输出文件流
HttpResponse输出文件: Response.Clear(); Response.ContentType = "application/octet-stream"; //通 ...
- jwplayer 禁止视频的快进,但是可以后退(已实现)
一直在研究.net 的视频播放,最近做起了jwplayer,然后项目要求是视频不能快进,但是可以重复观看已经看过的视频资源. 很简单 在标签<script> 中定义两个变量 var max ...
- Omi应用md2site发布-markdown转网站利器
写在前面 Md2site是基于Omi的一款Markdown转网站工具,使用简单,生成的文件轻巧,功能强大. 当我们想把一堆markdown文档转成网站时,你可能有许多选择,倘若选择 md2site , ...
- smarty实例登陆、显示、分页
1.先建立登陆页面,登陆页面的PHP文件和HTML文件是分开写的. 先建立一个登陆页的PHP文件, <?php include("../init.inc.php");//引入 ...
- Java并发之线程异常捕获
由于线程的本质特性,使得你不能捕获从线程中逃逸的异常,如: import java.util.concurrent.ExecutorService; import java.util.concurre ...