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. Java之路——名词解释(一)

    一.开篇 许多人在初接触Java的时候,都会被各种Java的英文缩写名词给弄得头晕脑胀.看一个技术,内容里又会有一堆其他的技术名词,看了半天不知所云.尝试去查一下这些名词的解释,除了非常学术性的解释之 ...

  2. php查询,多条件查询

    单条件查询: 1.先要有一张表,显示出表中的数据: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  3. P177 test 6-4 UVa439

    //P177 test 6-4 UVa439 #include<cstdio> #include<cstring> #include<queue> using na ...

  4. github fork, star and watch

    1 git fork git clone原版本的话,只有读权限,是不能直接把修改提交到服务器的. git fork会创建一个副本,然后就可以在这个上面进行开发了,开发了之后可以通过pull reque ...

  5. Linux下ls命令显示符号链接权限为777的探索

    Linux下ls命令显示符号链接权限为777的探索 --深入ls.链接.文件系统与权限 一.摘要 ls是Linux和Unix下最常使用的命令之一,主要用来列举目录下的文件信息,-l参数允许查看当前目录 ...

  6. 【转】搜索引擎选择: Elasticsearch与Solr

    原文地址:http://i.zhcy.tk/blog/elasticsearchyu-solr/ Elasticsearch简介 Elasticsearch是一个实时的分布式搜索和分析引擎.它可以帮助 ...

  7. 概念 : 过程 : 前台login

    为了解决自动登入.访问权限机制.登入权限而诞生了这过程,过程需要概念来维护记忆. 通过singlePageAutoLoginLocalStorage, UIStateLocalStorage, Use ...

  8. nginx配置参数详解

    配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍 ...

  9. Python编程快速上手——让繁琐工作自动化学习笔记

    第一部分 基本语法 1.字符串不能直接和数字相加,要用str()转一下:但是可以和数字相乘,用于表示多个字符串复制:字符串不能和浮点数直接结合,字符串可以和字符串直接相加: 2.输入函数用input( ...

  10. oracle目录操作

    1.创建目录 create directory dir_name as 'dir_path'  (dir_path必须事先手动创建) 2.授权 grant read,write on director ...