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题解的更多相关文章

  1. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  2. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  5. AtCoder Beginner Contest 173 题解

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

  6. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

  7. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  8. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  9. AtCoder Beginner Contest 151 题解报告

    总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...

随机推荐

  1. 《半吊子全栈系列:Boostrap3》

    前言:后端开发做网站 几年前,作为一名纯粹后端Java开发人员,对JS还没开窍,对于页面只停留在<十天学会DIV+CSS>这种程度,但是我又想做网站怎么办? 这时候Boostrap3出现了 ...

  2. 使用光盘iso实现Linux操作系统的自动安装部署

    前边写了一篇使用 PXE 的方式批量安装操作系统,不是任何时候任何地方都有环境来通过 PXE 方式来进行安装.如果此时需要通过光盘安装,默认的情况下是通过交互式方式进行安装,其实也可以通过 kicks ...

  3. Python爬虫爬取qq视频等动态网页全代码

    环境:py3.4.4 32位 需要插件:selenium BeautifulSoup xlwt # coding = utf-8 from selenium import webdriverfrom ...

  4. Matlab中plot函数全功能解析

    Matlab中plot函数全功能解析 功能 二维曲线绘图 语法 plot(Y)plot(X1,Y1,...)plot(X1,Y1,LineSpec,...)plot(...,'PropertyName ...

  5. HTML学习二

    继续上一次的学习: <html> <head> <title>新增雇员</title> <script language="javasc ...

  6. 快看我解决了一个Nginx的小问题

    前言 最近小编写项目的时候,需要用到Nginx服务器,对于Nginx正常安装就好了详情见[我是传送门],正当一切安好的时候问题来了,这台服务器的80端口竟然被占用了,什么鬼?怎么办,只有改端口.具体方 ...

  7. 《C#语言和数据库技术基础》单词必备

    <C#语言和数据库技术基础> 第一章1..NET Framework   框架2.sharp            尖锐,强烈的3.application      应用程序4.devel ...

  8. CentOs下安装PHP环境的步骤

    前言 在CentOs环境下安装php开发环境,需要首先安装一些源文件,然后使用yum命令直接安装即可,在Fedora 20 源中已经有了PHP的源,直接可以使用以下命令安装即可: # yum inst ...

  9. Java设计模式之《职责链模式》及应用场景

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6530089.html 职责链模式(称责任链模式)将请求的处理对象像一条长链一般组合起来,形 ...

  10. Java面试09|多线程

    1.假如有Thread1.Thread2.Thread3.Thread4四条线程分别统计C.D.E.F四个盘的大小,所有线程都统计完毕交给Thread5线程去做汇总,应当如何实现? 把相互独立的计算任 ...