这套题我只写了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. WPF 通过透明度遮罩和变换制作倒影效果

      倒影效果 代码 <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http:/ ...

  2. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十五║初探SSR服务端渲染(个人博客二)

    缘起 时间真快,现在已经是这个系列教程的下半部 Vue 第 12 篇了,昨天我也简单思考了下,可能明天再来一篇,Vue 就基本告一段落了,因为什么呢,这里给大家说个题外话,当时写博文的时候,只是想给大 ...

  3. mysql的学习笔记(二)

    1.数据类型,存储的类型. 整型 TINYINT 有符号-128到127 无符号值:0到255 1字节 SMALLINT 有符号 -32768到32767 0到65535 2字节 MEDIUMINT ...

  4. C# 中的Async 和 Await 的用法详解

    众所周知C#提供Async和Await关键字来实现异步编程.在本文中,我们将共同探讨并介绍什么是Async 和 Await,以及如何在C#中使用Async 和 Await. 同样本文的内容也大多是翻译 ...

  5. Swagger如何访问Ocelot中带权限验证的API

    先亮源代码:https://github.com/axzxs2001/Asp.NetCoreExperiment/tree/master/Asp.NetCoreExperiment/SwaggerDe ...

  6. 【朝花夕拾】Android安全之(一)权限篇

    前言        从Android6.0开始,Android系统对权限的处理产生了很大的变化.如果APP运行的设备系统版本为Android6.0或更高,并且target在23或更高,那么danger ...

  7. C#反射调用方法实例

    下面是两个反射的实例 案例1: 动态调用类中的方法.传入参数,并获得返回值. xxxx:类名 Event:类中的方法 pra1,pra2,pra3:方法对应的入参 DoRet:方法返回的执行结果 Ty ...

  8. WebApiClient的JsonPatch局部更新

    1. 文章目的 随着WebApiClient的不断完善,越来越多开发者选择WebApiClient替换原生的HttpClient,本文将介绍使用WebApiClient来完成JsonPatch提交的新 ...

  9. Python编程从入门到实践笔记——用户输入和while循环

    Python编程从入门到实践笔记——用户输入和while循环 #coding=utf-8 #函数input()让程序暂停运行,等待用户输入一些文本.得到用户的输入以后将其存储在一个变量中,方便后续使用 ...

  10. Eureka的工作原理以及它与ZooKeeper的区别

    1.Eureka 简介: Eureka 是 Netflix 出品的用于实现服务注册和发现的工具. Spring Cloud 集成了 Eureka,并提供了开箱即用的支持.其中, Eureka 又可细分 ...