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/ ...
随机推荐
- C#表达式和语句
表达式由操作数 (operand) 和运算符 (operator) 构成.表达式的运算符指示对操作数适用什么样的运算.运算符的示例包括+.-.*./ 和 new.操作数的示例包括文本.字段.局部变量和 ...
- FastDFS+Nginx部署详细教程
本例使用到的所有tar和zip包地址:http://download.csdn.net/detail/corey_jk/9758664 本例中使用CentOS1.CentOS2两台机器实现. 1 GC ...
- "ORA-01460: 转换请求无法实现或不合理"及C#操作Blob总结
class BlobDemo { private static readonly string ConnectionString = "Data Source=Tcco;User ID=sc ...
- 学生管理系统(C语言)
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 3 #define LEN ...
- TCP协议详解
TCP协议详解 一.TCP协议 1.TCP 通过以下方式提供可靠性: · ◆ 应用程序分割为TCP认为最合适发送的数据块.由TCP传递给IP的信息单位叫做报文段. · ◆ 当TCP发出一个报文段后 ...
- BI数据分析中KPI,KGI,CSF概念
1. 行为产生数据 先来谈一谈,自己对数据基础概念的思考.我认为首先要建立的核心观点是:行为产生数据. 翻译一下这个核心观点.意思就是,当我们在思考或描述数据相关需求的时候,必然要包含这样的语素:&q ...
- HttpRequest获取文件流,HttpResponse输出文件流
HttpResponse输出文件: Response.Clear(); Response.ContentType = "application/octet-stream"; //通 ...
- 每天一个Linux命令(05)--rm命令
自从学会了用mkdir创建目录之后,整个系统里就只能看到一堆空目录了,囧~ 那么今天我们来学一下如何清理这些空目录吧--rm命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录 ...
- 关于hosts文件的原理与制作
由于需要整理的关于hosts的文件 关于hosts文件的原理与制作1.什么是hosts文件hosts文件是一个没有扩展名的系统文件,hosts文件用于存储计算机网络中节点信息的文件,它是可以将主机名映 ...
- 数据的增删改查(三层)<!--待补充-->
进行数据操作必然少了对数据的增删改查,用代码生成器生成的代码不是那么满意!方便在今后使用,这里就主要写“数据访问层(Dal)” 既然这里提到三层架构:有必要将三层内容在这里详细介绍一下(待补充) 注: ...