这套题我只写了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. WireShark捕获HTTPS

    firefox,chrome会将 TLS 会话中使用的对称密钥保存在外部文件中. 1.建立环境变量 linux,mac 使用export建立变量:export SSLKEYLOGFILE=/tmp/s ...

  2. docker 备注

    1.docker 安装 #安装环境为centos yum -y install docker service docker start #测试是否安装成功,可执行命令 docker run hello ...

  3. linux shell 备注(一)

    1.特殊字符 #!/bin/bash # $表示当前PID ID echo $$ # $n是shell脚本的参数,当0是第一个参数,即文件名 # $#是shell当前脚本的参数个数 # 例如:sh03 ...

  4. String、StringBuffer和StringBuilder类的区别

    Java提供了String.StringBuffer和StringBuilder类来封装字符串,并提供了一系列操作字符串对象的方法. 它们的相同点是都用来封装字符串:都实现了CharSequence接 ...

  5. 【Python实践-4】切片操作去除字符串首尾的空格

    #利用切片操作,实现一个trim()函数,去除字符串首尾的空格,注意不要调用str的strip()方法 def trim(s): while s[0:1]==' ': s=s[1:] while s[ ...

  6. php载入脚本的几种方式对比

    require require_once include include_once 共同点: 都可以在当前 PHP 脚本文件执行时载入另外一个 PHP 脚本文件. require 和 include ...

  7. Java笔试题库之选题题篇【1-70题】

    1.下面中哪两个可以在A的子类中使用:( ) class A { protected int method1 (int a, int b) { return 0; } } A. public int ...

  8. InkImageDataSetGenerator-开源一个可用于机器学习的书写轨迹图片生成的小工具

    这是一个简单易用的图片数据集生成小工具,基于OpenCV和UWP Ink API,它可以根据指定的手写轨迹生成一系列各个角度的图片.每张图片的尺寸和总体数量都是可以指定的,均存放在统一的生成目录中.h ...

  9. ASP.NET Core Web API 集成测试中使用 Bearer Token

    在 ASP.NET Core Web API 集成测试一文中, 我介绍了ASP.NET Core Web API的集成测试. 在那里我使用了测试专用的Startup类, 里面的配置和开发时有一些区别, ...

  10. okhttputils【 Android 一个改善的okHttp封装库】使用(一)

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 本文使用的OKHttp封装库是张鸿洋(鸿神)写的,因为在项目中一直使用这个库,所以对于一些常用的请求方式都验证过,所以特此整理下. ...