标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4074 Accepted Submission(s): 1858
if(‘a‘<=str[i] && str[i]<=‘z‘)//处理小写字母
{
open[i]=min(open[i-1]+2,close[i-1]+2);
//到输入第i个小写字母的时候此时要求灯是开着的,如果输入前一个字母的时候大写灯是开着的,则要按Shift再输入字母。
//如果输入前一个字母大写灯是关着的,则输入字母再打开大写灯。
close[i]=min(open[i-1]+2,close[i-1]+1);
}
else//处理大写字母
{
open[i]=min(open[i-1]+1,close[i-1]+2);
close[i]=min(open[i-1]+2,close[i-1]+2);
}
初始化的时候要注意
open[0]=1; 因为一开始大写灯是关着的
close[0]=0;
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<stdlib.h> #include<queue> #include<stack> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=100+5; const int INF=0x3f3f3f3f; const double EPS=1e-9; int dir4[][2]={{0,1},{1,0},{0,-1},{-1,0}}; int dir8[][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}}; int dir_8[][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}}; int kase,len,open[MAXN],close[MAXN]; char str[MAXN]; int main() { scanf("%d",&kase); while(kase--) { scanf("%s",str+1); memset(open,0,sizeof(open)); memset(close,0,sizeof(close)); open[0]=1; int i; for(i=1;str[i];i++) { if(‘a‘<=str[i] && str[i]<=‘z‘)//小写 { open[i]=min(open[i-1]+2,close[i-1]+2); close[i]=min(open[i-1]+2,close[i-1]+1); } else//大写 { open[i]=min(open[i-1]+1,close[i-1]+2); close[i]=min(open[i-1]+2,close[i-1]+2); } } printf("%d\n",min(open[i-1]+1,close[i-1])); } return 0; }
标签:
原文地址:http://www.cnblogs.com/clliff/p/4248298.html