话说新的萌萌的图 来了一波呀~ 想起了叉姐的头像 Orz
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
AC代码如下:
//
// Created by TaoSama on 2015-05-27
// Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
string s;
int n;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
while(cin >> s >> n) {
int c = s.size() / n;
//cout << c<<endl;
if(s.size() % n != 0) {
cout << "NO\n";
continue;
}
bool yes = true;
for(int i = 0; i < s.size(); i += c) {
for(int j = i, k = i + c - 1; j < k; ++j, --k) {
if(s[j] != s[k]) {
yes = false;
break;
}
}
if(!yes) break;
}
if(yes) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
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
AC代码如下:
//
// Created by TaoSama on 2015-05-27
// Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int n, m, q, a[505][505], Max[505];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n; ++i) {
int t = 0, ct = 0;
for(int j = 1; j <= m; ++j) {
scanf("%d", &a[i][j]);
if(a[i][j]) {
++ct;
t = max(t, ct);
} else ct = 0;
}
Max[i] = t;
}
while(q--){
int x, y; scanf("%d%d", &x, &y);
a[x][y] = !a[x][y];
int ct = 0, t = 0;
for(int i = 1; i <= m; ++i){
if(a[x][i]) {
++ct;
t = max(t, ct);
} else ct = 0;
}
Max[x] = t;
printf("%d\n", *max_element(Max + 1, Max + 1 + n));
}
return 0;
}
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.

So, if height of Xaniar is h1 and
height of Abol is h2,
after one second height of Xaniar will become and
height of Abol will become
where x1, y1, x2 and y2 are
some integer numbers and
denotes
the remainder of amodulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠ a1 and h2 ≠ a2.
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
5 4 2 1 1 0 1 2 3
3
1023 1 2 1 0 1 2 1 1
-1
//
// Created by TaoSama on 2015-05-27
// Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
long long m, h1, a1, x1, y1, h2, a2, x2, y2;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin >> m;
cin >> h1 >> a1 >> x1 >> y1;
cin >> h2 >> a2 >> x2 >> y2;
long long ans = 0;
//求a的不循环节长
while(h1 != a1) {
h1 = (h1 * x1 + y1) % m;
h2 = (h2 * x2 + y2) % m;
++ ans;
if(ans > m) {
cout << "-1\n";
return 0;
}
}
if(h2 == a2) {
cout << ans << "\n";
return 0;
}
long long per = 0, px2 = 1, py2 = 0;
//a的循环节长度
while(per == 0 || h1 != a1) {
h1 = (h1 * x1 + y1) % m;
px2 = (px2 * x2) % m;
py2 = (py2 * x2 + y2) % m;
++per;
if(per > m) {
cout << "-1\n";
return 0;
}
}
long long cycle = 0;
//来暴力匹配下b 上界是m/per 直接写m也行
while(h2 != a2) {
h2 = (px2 * h2 + py2) % m;
++cycle;
if(cycle > m) {
cout << "-1\n";
return 0;
}
}
ans += per * cycle;
cout << ans << "\n";
return 0;
}
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strengthof a group is the minimum height of the bear in that group.
Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.
The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.
The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
10 1 2 3 4 5 4 3 2 1 6
6 4 4 3 3 2 2 1 1 1
用单调栈来维护 以a[i]为最小的两个区间边界 单调栈是
j < i, a[j] < a[i]的最大j
j > i a[j] < a[i]的最小j
说白了a[j] >=a[i]的左右两个边界 这一点也可以用dp的思想来维护
然后这个边界内都以a[i]为最小值 然后ans显然有一个性质 ans1 >= ans2 >= ans3 >= ... >= ans_n
然后用partial sum的思想取一下max 然后输出就好了
AC代码如下:
//
// Created by TaoSama on 2015-05-27
// Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int n, a[N], l[N], r[N], ans[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", a + i);
stack<int> s;
for(int i = 1; i <= n; ++i){
while(s.size() && a[s.top()] >= a[i]) s.pop();
l[i] = s.size() ? s.top() : 0;
s.push(i);
}
while(s.size()) s.pop();
for(int i = n; i >= 1; --i){
while(s.size() && a[s.top()] >= a[i]) s.pop();
r[i] = s.size() ? s.top() : n + 1;
s.push(i);
}
/*for(int i = 1; i <= n; ++i)
cout<<l[i]<<' ';
cout<<endl;
for(int i = 1; i <= n; ++i)
cout<<r[i]<<' ';
cout<<endl;*/
for(int i = 1; i <= n; ++i){
int width = r[i] - l[i] - 1;
ans[width] = max(ans[width], a[i]);
}
/*for(int i = 1; i <= n; ++i)
cout<<ans[i]<<' ';
cout<<endl;*/
for(int i = n - 1; i >= 1; --i)
ans[i] = max(ans[i], ans[i+1]);
for(int i = 1; i <= n; ++i)
printf("%d%c", ans[i], i == n ? '\n' : ' ');
return 0;
}
//
// Created by TaoSama on 2015-05-28
// Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int n, a[N], l[N], r[N], ans[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", a + i);
for(int i = 1; i <= n; ++i) l[i] = r[i] = i;
for(int i = 1; i <= n; ++i){
while(a[l[i] - 1] >= a[i])
l[i] = l[l[i] - 1];
}
for(int i = n; i >= 1; --i){
while(a[r[i] + 1] >= a[i])
r[i] = r[r[i] + 1];
}
for(int i = 1; i <= n; ++i){
int w = r[i] - l[i] + 1;
ans[w] = max(ans[w], a[i]);
}
for(int i = n - 1; i >= 1; --i)
ans[i] = max(ans[i], ans[i + 1]);
for(int i = 1; i <= n; ++i)
printf("%d%c", ans[i], i == n ? '\n' : ' ');
return 0;
}