这套题我只写了a, b, c。。  对不起,是我太菜了。

A:思路:就是直接简化为一个矩阵按照特定的步骤从一个顶角走到与之对应的对角线上的顶角。如图所示。

  

解释一下特定的步骤,就像马走日,象走田一样。你的步骤只能走(x-a, y-b), (x+a, y-b), (x-a, y+b), (x+a, y+b)这几种。

思路:假设高度为h, 宽度为w。 则如果 h%b==0&& w%a==0时,则一定能走到角落里。

       还有一种走法:就是先是正常的碰撞,最后几下就斜着走。这样的规律就是 h/b%2==w/a%2,  其实也不难理解。就是从横竖两个角度看待这个过程。

            

#include<iostream>
#include<algorithm>
using namespace std; int n, m, x, y, a, b, oo = 1e9; int f(int n, int m){
int u = max(n - x, x - n), v = max(m - y, y - m);
if (u%a || v%b || u / a % != v / b % )
return oo;
return max(u / a, v / b);
} int main(){
cin >> n >> m >> x >> y >> a >> b;
int ans = min(min(f(, m), f(, )), min(f(n, ), f(n, m)));
if (ans == oo || (ans && (n <= a || m <= b)))
cout << "Poor Inna and pony!" << endl;
else cout << ans << endl;
}

B题:给你一个字符串,然后相邻两个字符相加和为9,则说明可以合并。

   思路:如果,一个字母与左右相邻的字符不能合并为9,是不是它相当于是一个相隔符号对整个方案数没有作用。

      那么真正有用的就是那段连续的可以合并为9的字符串。那么相当于,我们把一个字符串把两边都不能合并为9的字符去除,这样就留下几个连续的子串。

      最后的答案,就是这几个子串的组合数即可。

      现在,来处理子串。现在来分析性质,1:如果子串的长度为偶数,则为了最多合并则合并的方法是唯一的。2:如果,子串的长度是奇数,所以也就是说总会有一个字符不被合并。

      也就是在这个子串中选择一个字符被留下,则方案数就是(n+1)/2.

#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
const int INF=0x3f3f3f3f, maxn=1e5+;
char s[maxn];
int main(){
while(cin>>s){
int n=strlen(s);
ll ans=;
for(int i=;i<n-;++i)
if(s[i]-''+s[i+]-''==)
{
int num=;
while(i<n-&&s[i]-''+s[i+]-''==)num++, ++i;
if(num&)ans*=1LL*(num+)/;
}
cout<<ans<<endl;
}
}

C题:这是一个DFS题。

   注意:处理边界和形成循环得情况。

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e3 + ;
char str[maxn][maxn];
bool vis[maxn][maxn];
int cnt[maxn][maxn];
string DIMA = "DIMA";
int dx[] = { , -, , };
int dy[] = { , , , - };
bool endless = ; void dfs(int x, int y, int n){
if (endless)return;
n = (n + ) % ;
int num = ;
for (int i = ; i <= ; ++i)
{
int x1 = x + dx[i];
int y1 = y + dy[i];
if (str[x1][y1] == DIMA[n]){
if (vis[x1][y1]){
endless = ;
return;
}
else if (!cnt[x1][y1]){
vis[x1][y1] = ;
dfs(x1, y1, n);
num = max(num, cnt[x1][y1]);
vis[x1][y1] = ;
}
else num = max(num, cnt[x1][y1]);
}
}
if (!cnt[x][y] && n == )num++;
cnt[x][y] = num;
return;
} int main(){
int n, m;
cin >> n >> m;
for (int i = ; i <= n; ++i)
cin >> str[i] + ;
int ans = ;
for (int i = ; i <= n;++i)
for (int j = ; j <= m;++j)
if (str[i][j] == 'D'&&!cnt[i][j]){
dfs(i, j, ); ans = max(ans, cnt[i][j]);
}
if (endless)cout << "Poor Inna!" << endl;
else if (ans == )cout << "Poor Dima!" << endl;
else cout << ans << endl;
return ;
}

codeforces div2 220 解题的更多相关文章

  1. codeforces Round #258(div2) D解题报告

    D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. codeforces Round #259(div2) C解题报告

    C. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  3. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. codeforces 31C Schedule 解题报告

    题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...

  5. codeforces 499B.Lecture 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...

  6. codeforces 495C. Treasure 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...

  7. codeforces 490B.Queue 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...

  8. CodeForces 166E -Tetrahedron解题报告

    这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...

  9. codeforces 489A.SwapSort 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...

随机推荐

  1. Java内存模型一个经典例子-指令重排序与CPU指令多发射导致执行结果异常

    先上代码: import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; ...

  2. Linux下Zookeeper安装使用

    1. 下载 下载地址,选择稳定的版本,比如3.4.13,beta为在测版本 2. 复制到任意的目录,解压 3. 修改配置文件 配置文件位于conf目录下,原配置文件为zoo_sample.cfg,更改 ...

  3. AutoStartUtil【打开自启动设置界面】

    参考资料 Android6.0 打开自启动管理页面(华为.小米) Android打开自启动设置页面 Android 机型设置自启动的跳转界面 代码 注意:需要搭配<RomUtil[Android ...

  4. SQL优化 MySQL版 - 单表优化及细节详讲

    单表优化及细节详讲 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 注:本文章需要MySQL数据库优化基础或观看前几篇文章,传送门: B树索引详讲(初识SQL优化,认识索引):htt ...

  5. Windows10下安装Docker的步骤

    一.启用Hyper-V 打开控制面板 - 程序和功能 - 启用或关闭Windows功能,勾选Hyper-V,然后点击确定即可,如图: 点击确定后,启用完毕会提示重启系统,我们可以稍后再重启. 二.安装 ...

  6. GoLang simple-project-demo-02

    GoLang 有很多种数据类型:字符型,整型,浮点型,布尔型.下面是基础例子: package main import "fmt" func main() { fmt.Printl ...

  7. 点击菜单选项,右侧主体区新增子界面(Tab)的实现

    今天是2019年小年后一天,还有三天回家过年. 今天记录一下一种前端页面的效果的实现,这种效果很常见,一般用于网站后台系统的前端页面.一般后台系统会分为顶部导航栏,左边的菜单栏和右边的主体区.有一种效 ...

  8. C# 反射 判断类的延伸类型

    判断类型是否被继承.实现 1.判断是否实现了指定接口 添加测试类: public class TestClass2 : TestClass1 { } public class TestClass1 : ...

  9. 杂牌机搞机之旅(二)————移植TWRP第三方Recovery并刷入

    原本想把杂牌机作为android破解和开发的测试机,破解的话肯定是安装框架的嘛,毕竟有些是要涉及到脱壳 . 但是,我尝试安装xposed的时候,手机卡在了开机界面,也就是magisk出现了错误,如果想 ...

  10. Servlet练习:实现增删改查的综合练习

    ---恢复内容开始--- 本文为原创,转载请注明出处:https://www.cnblogs.com/Tom-shushu/p/9383066.html 本篇内容主要介绍:通过Servlet,JSP, ...