CodeForces 548
1 second
256 megabytes
standard input
standard output
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).
The second line contains integer k (1 ≤ k ≤ 1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
saba
2
NO
saddastavvat
2
YES
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
题目思路:看串是否能被 k 整除,如果能,在每段里判断这段是否是回文串。
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream> using namespace std; int main()
{
int k;
char str[];
char s1[];
gets(str);
scanf("%d", &k); int len = strlen(str);
bool flag = false;
if(len % k == ) {
int l = len / k;
for(int i = ; i != len && !flag; i += l) {
for(int j = ; j != l && !flag; ++j) {
if(str[i+j] != str[i+l--j]) {
flag = true;
}
}
}
if(flag == true) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} else {
cout << "NO" << endl;
}
return ;
}
2 seconds
256 megabytes
standard input
standard output
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
After each round, print the current score of the bears.
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
3
4
3
3
4 思路:给你个图,统计每行中,最多有几个连续的“1”,然后再在没行里找个最大的。 注意不能再具体查询的时候再对图进行暴力,复杂度太高。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int arr[][];
int sum[][];
int ans[];
int main() {
int n, m, q;
cin >> n >> m >> q;
memset(sum, , sizeof(sum));
memset(ans, , sizeof(ans));
for(int i = ; i != n; ++i) {
scanf("%d", &arr[i][]);
sum[i][] = (arr[i][] == ) ? : ;
for(int j = ; j != m; ++j) {
scanf("%d", &arr[i][j]);
if(arr[i][j])
sum[i][j] = sum[i][j-] + ;
else
sum[i][j] = ;
}
for(int j = ; j != m; ++j){
ans[i] = max(ans[i], sum[i][j]);
}
} int x, y, Max = ;
while(q--) {
scanf("%d %d", &x, &y);
arr[x-][y-] = arr[x-][y-] == ? : ;
sum[x-][] = (arr[x-][] == ) ? : ;
for(int i = ; i != m; ++i) {
if(arr[x-][i])
sum[x-][i] = sum[x-][i-] + ;
else
sum[x-][i] = ;
}
ans[x-] = ;
for(int i = ; i != m; ++i) {
ans[x-] = max(ans[x-], sum[x-][i]);
}
for(int i = ; i != n; ++i) {
Max = max(Max, ans[i]);
}
printf("%d\n", Max);
Max = ;
}
return ;
}
CodeForces 548的更多相关文章
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces Round 548 (Div. 2)
layout: post title: Codeforces Round 548 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #548 (Div. 2) F splay(新坑) + 思维
https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\), ...
- Codeforces Round #548 (Div. 2) E 二分图匹配(新坑) or 网络流 + 反向处理
https://codeforces.com/contest/1139/problem/E 题意 有n个学生,m个社团,每个学生有一个\(p_i\)值,然后每个学生属于\(c_i\)社团, 有d天,每 ...
- CodeForces Round #548 Div2
http://codeforces.com/contest/1139 A. Even Substrings You are given a string s=s1s2…sns=s1s2…sn of l ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块
C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #548
没打,简单补档 C.Edgy Trees 容斥,把黑边断掉数联通块,每个联通块贡献$siz^k$ #include<cstdio> #include<cstring> #inc ...
- Codeforces Round #548 (Div. 2) D 期望dp + 莫比乌斯反演
https://codeforces.com/contest/1139/problem/D 题意 每次从1,m中选一个数加入队列,假如队列的gcd==1停止,问队列长度的期望 题解 概率正着推,期望反 ...
随机推荐
- HTML2
1. IIS是一个软件,在"客户端服务器"模型中,它是服务器端软件,它主要提供基于HTTP的文档服务,主要是WWW 的发送,以及FTP的文件下载服务. VS提供了" ...
- C#------连接SQLServer和MySQL字符串
<connectionStrings> <add name="ConnectionStrings" connectionString="Data Sou ...
- Root--超级用户
http://www.shuame.com/root/ root (计算机术语言) ROOT存在于Linux系统.UNIX系统(如AIX.BSD等)和类UNIX系统(如稳定到服务器都在用的Debia ...
- C#环境
- Loadrunner安装
安装参考网址:http://www.cnblogs.com/yangxia-test/archive/2012/10/30/2746621.html 本人验证过的,不自己写了 另附Loadrunner ...
- jquery + header
官网上搜索headers 基本用法(直接用下楼上的代码了) $.ajax({ //请求类型,这里为POST type: 'POST', //你要请求的api的URL url: url , //是否使用 ...
- golang笔记——map
通过 new 创建的引用类型对象是不完整创建,比如 map,它仅分配了字典类型本身所需的内存(指针包装),而没有分配键值存储内存,也没有初始化散列桶等内部属性,因此无法工作,如下代码就是错误的: p ...
- Matlab学习笔记(一)—— 三维图形绘制
这学期公选课选的是MATLAB,所以准备把这学期所学习的整理到博客上,作为记录,哇咔咔~ 一.三维函数图: x=cos(t), y=sin(t), z=t %≤t ≤*pi t=:*pi; %t的取值 ...
- php 操作数组 (合并,拆分,追加,查找,删除等)
1. 合并数组 array_merge()函数将数组合并到一起,返回一个联合的数组.所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加.其形式为: array array_merg ...
- python之路五
内建模块 time和datetime 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现 ...