这套题我只写了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. 如何用GoldWave批量删除mp3文件开头65秒?

    具体操作如下: 一.打开goldwave--文件--批处理 二.批处理设置:     添加需处理的文件或文件夹(右侧)         1.转换:设置转换格式.         2.处理:       ...

  2. 白话kubernetes的十万个为什么(持续更新中...) - kubernetes

    Kubernetes简称? 答:k8s或kube. Kubernetes是什么? 答:由Google开发的一个强大的平台,可以在集群环境中管理容器化应用程序.本质上是一种特殊的数据库,里面存储的是能够 ...

  3. Scala实现Try with resources自动关闭IO

    在处理数据库连接或者输入输出流等场景时,我们经常需要写一些非常繁琐又枯燥乏味的代码来关闭数据库连接或输入输出流. 例如数据库操作: def update(sql: String)(conn: Conn ...

  4. vue项目向小程序迁移调研

    概述 今天调研了一下vue项目怎么向小程序迁移,有些心得,记录下来,供以后开发时参考,相信对其他人也有用. 基本上vue项目向小程序迁移不外乎2种方法,一种是用小程序的web-view组件,另一种是用 ...

  5. shell打印 菱形

    #!/bin/bashread -p "input the length: " n        for i in `seq 1 $n`do    for ((j=$n;j> ...

  6. 【Android Studio安装部署系列】一、JDK开发环境搭建

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 Android Studio安装后自带jre,这个自带jre的版本号肯定比最新的版本号要小. 但是如果项目中没有用到新版本jdk的特 ...

  7. 【Android Studio安装部署系列】五、新建你的第一个项目:HelloWorld

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 新建项目的步骤. 开始创建项目 如果是刚安装Android studio的话,点击Start a new Android Studi ...

  8. 学习ASP.NET Core Razor 编程系列十九——分页

    学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...

  9. 2018~第三届南宁市网络安全技术大赛~nnctf~write-up

    Web 1.超简单 分值:100 类型:WEB 已解决 题目:超简单的web题  http://gxnnctf.gxsosec.cn:12311/ 代码审计 <?php $white_list ...

  10. 浅谈SQL Server内部运行机制

    对于已经很熟悉T-SQL的读者,或者对于较专业的DBA来说,逻辑的增删改查,或者较复杂的SQL语句,都是非常简单的,不存在任何挑战,不值得一提,那么,SQL的哪些方面是他们的挑战 或者软肋呢? 那就是 ...