codeforces div2 220 解题
这套题我只写了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 解题的更多相关文章
- codeforces Round #258(div2) D解题报告
D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces Round #259(div2) C解题报告
C. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
- codeforces Round #258(div2) C解题报告
C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- codeforces 31C Schedule 解题报告
题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...
- codeforces 499B.Lecture 解题报告
题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...
- codeforces 495C. Treasure 解题报告
题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...
- codeforces 490B.Queue 解题报告
题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...
- CodeForces 166E -Tetrahedron解题报告
这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...
- codeforces 489A.SwapSort 解题报告
题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...
随机推荐
- Ambari安装HDP问题:User root is not allowed to impersonate anonymous.User: hcat is not allowed to impersonate ambari-qa
User root is not allowed to impersonate anonymous 修改hadoop 配置文件 etc/hadoop/core-site.xml,加入如下配置项 < ...
- eShopOnContainers 知多少[4]:Catalog microservice
引言 Catalog microservice(目录微服务)维护着所有产品信息,包括库存.价格.所以该微服务的核心业务为: 产品信息的维护 库存的更新 价格的维护 架构模式 如上图所示,本微服务采用简 ...
- 多线程工具类:CountDownLatch、CyclicBarrier、Semaphore、LockSupport
◆CountDownLatch◆ 假如有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以.比如你想要买套房子,但是呢你现在手上没有钱.你得等这个月工资发了.然后年终奖发了.然后朋友借你得钱 ...
- 使用前端技术和MySQL+PHP制作自己的一个个人博客网站
源代码地址:https://github.com/YauCheun/BlogCode 我的博客网站地址:http://www.yublog.fun/ 制作前景: 想拥有一个自己独自开发的一个小型博客网 ...
- React教程(一) React介绍与搭建
React的介绍: React来自于Facebook公司的开源项目 React 可以开发单页面应用 spa(单页面应用) react 组件化模块化 开发模式 React通过对DOM的模拟(虚拟dom) ...
- Scrapy-redis<数据库篇>
scrapy-redis爬虫数据库连接部分——windows准备做salve,Linux准备做master开展工作 首先处理简单的windows熟悉的环境——安装Redis服务和Redis可视化~可视 ...
- springcloud之自定义简易消费服务组件
本次和大家分享的是怎么来消费服务,上篇文章讲了使用Feign来消费,本篇来使用rest+ribbon消费服务,并且通过轮询方式来自定义了个简易消费组件,本文分享的宗旨是:自定义消费服务的思路:思路如果 ...
- Python编程从入门到实践笔记——异常和存储数据
Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...
- JDK源码分析(2)之 Array 相关
在深入了解 Array 之前,一直以为 Array 比较简单,但是深入了解后才发现其实挺复杂的.所以我把重要的写在最前面,但凡遇到和语言本身相关的问题,都可以查阅 Java Language and ...
- Mondrian + JPivot 环境配置
一.环境准备 特别说明:Mondrian + JPivot 环境笔者已整理调试通过,可直接部署运行. 1.1 环境要求 JDK1.8+ 1.2 环境包说明 从 https://pan.baidu.co ...