分析:直接模拟即可,这里用队列记录访问过的点,栈记录父节点。另外要注意的是在strlen(str)计算字符串的时候要预先计算出来保存在变量中,for直接用,如果for循环直接调用strlen,那么每次都会重新计算,该題字符串的数据量很大,就会存在大量的无用计算,还导致了一次TLE,唉!以前没注意到这里。
#include
#include
#include
#include
using name...
分类:
其他好文 时间:
2015-05-13 14:51:29
阅读次数:
103
分析:DFS即可。
#include
using namespace std;
bool map[21][21];
bool vis[21];
int ans[21],num,m;
void init()
{
int i,a;
memset(map,false,sizeof(map));
for(i=1;i<=20;i++) //构图
{
map[i][ci...
分类:
其他好文 时间:
2015-05-13 14:45:50
阅读次数:
139
分析:该題可以用线段树做,也可以用树状数组做;感觉树状数组容易一些,这里就用树状数组了。这里保存字符数组的下标从1开始,树状数组初始化从3开始,因为只有大于等于3使才可能有符合要求的字串出现,最终计算L到R区间的个数时要用getsum(R)-getsum(L+1),因为可能有符合要求的str[L-1],str[L],str[l+1]也被算进去了,实际上他并不在区间L到R内。更新时要注意三种情况,P...
分类:
编程语言 时间:
2015-05-13 10:42:28
阅读次数:
173
分析:只需要求出最大公约数,然后枚举最大公约数的因子,把他们保存起来在求第K大的;因为是最大公约数的因子必然是两个数的因子。另外循环变量i和个数cnt都要声明为__int64,否则出错。
#include
#include
using namespace std;
__int64 gcd(__int64 x,__int64 y)
{
__int64 r;
while(y)
{
r=...
分类:
其他好文 时间:
2015-05-12 13:39:27
阅读次数:
135
分析:先根据询问求出每个纵向区间的最小公倍数(一列算一个区间),在根据询问判断每个横向区间的最大公约数是否和询问相同,若都相同则输出最终结果,否则不存在。
#include
using namespace std;
int a[1005];
struct NODE
{
int l,r,gcd;
} GCD[1005];
int gcd(int x,int y)
{
return ...
分类:
其他好文 时间:
2015-05-11 09:07:24
阅读次数:
180
分析:水题,主要是要注意几个细节。
#include
using namespace std;
char a[100005],A[100005];
char b[100005],B[100005];
void Process(char* p,int count,char* p2)
{
int pos;
bool is_real;
int i=0,k=0,j;
label:
...
分类:
其他好文 时间:
2015-05-10 19:00:07
阅读次数:
125
分析:可以用线段树做,但感觉麻烦。用优先队列,每次插入时都保留前k个大的数即可。
#include
#include
#include
using namespace std;
int main()
{
int n,k,j,c;
char b[2];
ios::sync_with_stdio(false);
while(cin>>n>>k)
{
priority_queue,g...
分类:
其他好文 时间:
2015-05-10 15:49:40
阅读次数:
118
分析:水题,题目居然这么长,全国邀请赛也有水题?strlen(a)返回的是无符号整形,strlen(a)-4会变为正的很大的数,还被RE了两次,唉!人老了。转换为int即可。
#include
using namespace std;
#define N 1000010
int main()
{
char a[N+10];
int ans,i;
ans=0;
while(gets(...
分类:
其他好文 时间:
2015-05-10 14:22:46
阅读次数:
108