love
TimeLimit: 5 Second MemoryLimit: 32 Megabyte
Totalsubmit: 14 Accepted: 4
Description
Long time ago,beautiful princess hc was caught by Devil zhy,and handsome prince cx went to zhy's cave to save hc.In zhy's cave,cx face a lock and must to solve.This lock is a string (s[0]~s[n-1]),and you can consider it is a circle,it means s[n-1] is followed by s[0],so it can be seen as many strings : s[0]~s[n-1]; s[1]~s[n-1],s[0]; s[2]~s[n-1],s[0]~s[1]; .....s[n-1],s[0]~s[n-2], and in these strings ,you shoule help cx find a Dictionary-order minnest one.
print the location of first character in the initial string ,and the string you find. If there exist many strings,find the minnest number.
Input
Every case include a A string (the length n is 0<n<=100000).Output
first line is a number stand for the location in the initial string.(the location is started from 0).second line is a string you find.
Sample Input
asyouknowcxisahandsomeboy
iamsorrybutiwanttosayzhyisadadiaosi
cabababababab
Sample Output
13
ahandsomeboyasyouknowcxis
26
adadiaosiiamsorrybutiwanttosayzhyis
1
ababababababc
Source
cx
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
const int maxn = 100100;
char ch[maxn];
int cnt;
bool ok[maxn];
int flag;
int main() {
while(~scanf("%s",ch)) {
int len = strlen(ch);
flag = 0;
for(int i=0;i<len;i++) ch[i+len] = ch[i];
ch[len + len] = 0;
int flag = 0;
for(int i=1;i<len;i++) if(strcmp(ch + flag , ch + i) > 0) flag = i;
printf("%d\n",flag);
for(int i=0;i<len;i++) printf("%c",ch[flag + i]);
puts("");
}
return 0;
}
LAM大逃亡
TimeLimit: 3 Second MemoryLimit: 32 Megabyte
Totalsubmit: 45 Accepted: 2
Description
话说正在LAM玩四驱车的时候,天空忽然电闪雷鸣,下起了倾盆大雨,LAM此时正在n*m广场的左上角(1,1)。现在开始每隔一秒钟将会有一道闪电劈在广场上。还有更严重的问题就是,广场上的坑由于下雨积满了水,也就是说积了水的地方将会导电,变成导电区域,如果闪电劈在一个导电的区域,电流将转播到所有与它连通的导电区域(一个区域和它上下左右四个区域连通。注意是导电区域,非导电区域就算连通也不会受影响)。现在已知第i秒,闪电将落在广场的(xi,yi)处,而LAM每秒可以向周围任意方向移动一格,那么LAM在(1,1),要以最短的时间(n+m-2)秒向出口(n,m)逃去,LAM想知道他有多少种不同的逃跑路线。由于方案数比较多,所以输出方案数%100000001的值。Input
对于每组数据,第一行2个整数 N,M。接下来N行每行M个数 描述广场, 1表示该区域是导电区域,0表示不是。
接下来N+M-2行每行2个整数X,Y 表示1~N+M-2秒内每秒雷电劈下的坐标。
3<=N,M<=1000 1<=X<=N; 1<=Y<=M;
Output
对于每组数据输出一行,如果方案数不为零,则输出一个整数表示总方案对 100000001后的值,否则输出“LAM is dead!”(不含引号)。Sample Input
3 3
0 0 1
1 0 0
1 0 0
1 2
2 1
1 3
2 2
Sample Output
2
Source
lrl
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
const int maxn = 1010;
int dp[maxn][maxn];
int n , m;
bool ok[maxn][maxn];
int vis[maxn][maxn];
int dd[maxn][maxn];
int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
bool inmap(int x,int y) {
return x >0 && y > 0 && x <= n && y <= m;
}
void dfs(int ti , int x , int y) {
if(!inmap(x,y)) return;
if(!dd[x][y]) return;
if(vis[x][y] == ti) return;
vis[x][y] = ti;
if(ti + 2 == x + y) ok[x][y] = 0;
forn(i,4) {
int xx = x + dir[i][0];
int yy = y + dir[i][1];
dfs(ti , xx , yy);
}
}
int main() {
while(~scanf("%d%d",&n,&m)) {
memset(ok,1,sizeof(ok));
memset(dp,0,sizeof(dp));
memset(vis,0,sizeof(vis));
for1(i,n) for1(j,m) scanf("%d",&dd[i][j]);
for1(ti , n + m - 2) {
int x , y;
scanf("%d%d",&x,&y);
if(ti + 2 == x + y) ok[x][y] = 0;
if(dd[x][y]) dfs(ti , x , y);
}
dp[1][1] = 1;
for1(i,n) for1(j,m) {
if(i + j == 2) continue;
if(!ok[i][j]) dp[i][j] = 0;
else {
dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 100000001;
}
}
/*printf("_default_\n");
for1(i,n) {
puts("");
for1(j,m) printf(" %d",dp[i][j]);
}
puts("ok?");
for1(i,n) {
puts("");
for1(j,m) printf(" %d",ok[i][j]);
}*/
if(dp[n][m] == 0) puts("LAM is dead!");
else printf("%d\n",dp[n][m]);
}
return 0;
}