#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
int main()
{
char a[];
scanf("%s",a);
LL s1=,sum=,len=strlen(a);
if(a[]=='Q') s1++;
for(int i=;i<len;i++)
{
if(a[i]=='Q'){s1++;}
if(a[i]=='A'&&s1!=)
{
LL s2=,s=s1;
if(a[i-]=='Q') s--;// 小心越界
for(int j=i+;j<strlen(a);j++)
if(a[j]=='Q') s2++;
sum+=s*s2;
}
}
cout<<sum<<endl;
}
// 超时代码
#include<iostream>
#include<string>
using namespace std;
int count=;
void bfs(string s,int i,int flag)
{
if(i>=(int)s.length()) return ;
if(flag==)
{
if(s[i]=='Q')
{
bfs(s,i+,flag+);
}
else bfs(s,i+,flag);
}
if(flag==)
{
if(s[i]=='A')
{
bfs(s,i+,flag+);
}
bfs(s,i+,flag);
}
if(flag==)
{
if(s[i]=='Q')
{
count++;
}
bfs(s,i+,flag);
}
}
int main()
{
string s;
cin>>s;
for(int i=;i<s.length()-;i++)
bfs(s,i,);
cout<<count<<endl;
}

相比两个方法  第一个少了回溯次;

B题:

#include <iostream>
using namespace std;
#define N 'W'+ 'W' + '#'
#define FOR(i,l,r) for(int i = l;i < r;i++)
char a[][];
int judge()
{
if(a[][] + a[][] + a[][] == N || a[][] + a[][] + a[][] == N)return ;
FOR(i,,)
if(a[i][]+a[i][]+a[i][]==N || a[][i]+a[][i]+a[][i] == N)return ;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int flag = ;
FOR(i,,)scanf("%s",a[i]);
if(!judge())
{
FOR(i,,)FOR(j,,)
if(a[i][j] == 'W')
{
a[i][j]='#';
if(judge())flag = ;
a[i][j]='W';
}
flag?puts("Emmm"):puts("Alice");
}
else puts("Bob");
}
return ;
}

代码精炼。正常要写100+;

最新文章

  1. mybatis进阶
  2. WebSocket桌面客户端工具
  3. 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
  4. poj 1006 中国剩余定理解同余方程
  5. Linux运维
  6. [Hadoop源码解读](四)MapReduce篇之Counter相关类
  7. photoshop中rgb与索引模式的区别
  8. nginx access log logrotate配置
  9. linux主机load average的概念&amp;&amp;计算过程&amp;&amp;注意事项
  10. bppm与AD域集成
  11. ios app网址说明
  12. sehll 小脚本的应用
  13. app后端设计(6)-- LBS
  14. [C]static变量详解
  15. system函数的应用
  16. arcgis api for flex 开发入门
  17. Delphi在Listview中加入Edit控件
  18. 微信小程序——template的使用方法
  19. [ios]Xcode常用快捷键
  20. windows 设置CapsLock键开启大写后使用shift键取消大写

热门文章

  1. 第一章 T-SQL查询和编程基础 T-SQL语言基础(1)
  2. kinit: Bad encryption type while getting initial credentials
  3. 搭建私有CA并基于OpenSSL实现双向身份认证
  4. windows下双击可运行的Java软件打包方案(转)
  5. 并查集+启发式合并+LCA思想 || 冷战 || BZOJ 4668
  6. 用xshell连接l自己的inux
  7. 高性能mysql 第7章 mysql高级特性之分区表
  8. 分布式中 CAP BASE ACID 理解(转载)
  9. mysql 主从 Last_IO_Errno错误代码说明
  10. k8sConfigMap资源