您的位置:首页 > 其它

srm 530

2015-06-01 23:39 232 查看

srm 529感觉题并不是很有趣,所以不打算写题解辣>_<

250

Solution

唔,这是个傻逼题,随便暴力下就好= =

Code

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
class GogoXCake {
public:
string solve( vector <string> cake, vector <string> cutter ) {
int m = cutter.size(), n = cutter[0].size();
for (int i = 0; i + m <= cake.size(); ++i) {
for (int j = 0; j + n <= cake[0].size(); ++j) {
bool canUse = true;
for (int x = 0; x < m; ++x)
for (int y = 0; y < n; ++y)
if (cutter[x][y] == '.' && cake[i + x][j + y] == 'X')
canUse = false;
if (canUse) {
for (int x = 0; x < m; ++x)
for (int y = 0; y < n; ++y)
if (cutter[x][y] == '.')
cake[i + x][j + y] = 'X';
}
}
}
for (int i = 0; i < cake.size(); ++i)
for (int j = 0; j < cake[0].size(); ++j)
if (cake[i][j] == '.')
return "NO";
return "YES";
}
};


500

Description:

给定一个邻接矩阵表示的图,求0∼n−10\sim n-1最多有多少条路径,满足这些路径按一定顺序排列后每条路径至少出现一条之前没有出现过的边。

Solution

感觉这是道非常好的题,可惜自己太弱,听别人讲了才会>_<

首先求出传递闭包,然后我们保留那些能从00到达并且能到n−1n-1的点,标记除0,n−10,n-1外所有点visited为false。

然后我们找一个没走过的点vv,从一个走过的点uu走到vv,然后把vv标记为走过。当所有点都标记为走过的时候,随意选一个没走过的边,都可以用已经走过的边形成一条路径。

所以最开始用来标记这n−2n-2个点一共用了n−1n-1条边,形成一条路径。其余m−(n−1)=m−n+1m-(n-1)=m-n+1条边每条边都形成一个新的路径,所以一共有1+m−n+1=m−n+21+m-n+1=m-n+2条路径。

真是一道很好的题

Code:

#include <bits/stdc++.h>
using namespace std;
const int N = 55;
bool g

;
class GogoXMarisaKirisima {
public:
int solve(vector <string> choices) {
int n = choices.size();
for (int i = 0; i < n; ++i) {
g[i][i] = 1;
for (int j = 0; j < n; ++j)
if (choices[i][j] == 'Y')   g[i][j] = 1;
}
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
g[i][j] |= g[i][k] & g[k][j];
if (!g[0][n - 1])   return 0;
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (choices[i][j] == 'Y' && g[0][i] && g[j][n - 1]) ++ans;
for (int i = 1; i < n - 1; ++i)
if (g[0][i] && g[i][n - 1]) --ans;
return ans;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: