a
【问题描述】
你是能看到第一题的 friends 呢。
——hja
何大爷对字符串十分有研究,于是天天出字符串题虐杀 zhx。

何大爷今天为字符串定义了新的权值计算方法。一个字符串

由小写字母组成,字符串的权值被定义为其中出现次数最多

的字符的次数减去出现次数最少的字符的次数。 (注意,在

讨论出现最少的字符的时候,该字符必须至少出现一次)现在

何大爷给你一个字符串,何大爷想知道这个字符串的所有子串

中权值最大的权值是多少?

【输入格式】
第一行一个整数?,代表字符串的长度。
接下来一行?个小写字母,代表该字符串。
【输出格式】
一行一个整数代表答案。
【样例输入】
10
aabbaaabab
【样例输出】
3
【数据范围与规定】
3。
60%的数据,1 ≤ ? ≤ 1000。
对于100%的数据,1 ≤ ? ≤ 10 6 .

题目大意:

求一个字符串子串的最多出现次数-最少出现次数的最大值。

题解:

30分做法O(n^3)枚举区间 扫最大最小值

60分做法O(26n^2)枚举区间 前缀和求最大最小值

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,maxx,minn,ans,sum[][];
char s[];
int main(){
scanf("%d",&n);scanf("%s",s+);
for(int i=;i<=n;i++){
for(int j=;j<=;j++)sum[i][j]=sum[i-][j];
int z=s[i]-'a'+;
sum[i][z]=sum[i-][z]+;
}
for(int i=;i<=n;i++){
for(int j=i;j<=n;j++){
if(i==j){
ans=max(ans,);
continue;
}
maxx=-;minn=;
for(int k=;k<=;k++){
int z=sum[j][k]-sum[i-][k];
if(z)minn=min(minn,z);
maxx=max(maxx,z);
}
ans=max(ans,maxx-minn);
}
}
printf("%d\n",ans);
return ;
}

60分

枚举右端点,前缀和优化。对于当前点x,答案为

sum[x][r]-sum[x][l-1]-(sum[z][r]-sum[z][l-1])

整理为

sum[x][r]-sum[z][r]-(sum[x][l-1]-sum[z][l-1])

我们已知x和sum[x][r],对于z我们枚举,

对于sum[x][l-1]-sum[z][l-1]我们需要一个最小的

用minv[x][y]表示sum[x]-sum[y]的最小值。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector> using namespace std; const int maxn=; int n,ans,p[][],minv[][],sum[],last[]; char s[maxn]; int main()
{
scanf("%d",&n);
scanf("%s",s+);
for (int a=;a<=n;a++)
{
int c=s[a]-'a';
sum[c]++;
last[c]=a;
for (int b=;b<;b++)
if (b!=c && sum[b]) ans=max(ans,max(sum[c]-sum[b]-minv[c][b]-(last[b]==p[c][b]),sum[b]-sum[c]-minv[b][c]-(last[b]==p[b][c])));
for (int b=;b<;b++)
{
if (sum[c]-sum[b]<minv[c][b]) minv[c][b]=sum[c]-sum[b],p[c][b]=a;
if (sum[b]-sum[c]<minv[b][c]) minv[b][c]=sum[b]-sum[c],p[b][c]=a;
}
}
printf("%d\n",ans); return ;
}

AC

如果视线和障碍物有公共点,那么我们认为视线会被阻挡,无法看见。

如果视线和镜子有公共点,那么我们认为发生了反射。反射的过程遵

循物理规律——入射角等于反射角,且反射光线与入射光线在镜子同

侧。也就是说,想要看见对方,Hja 和 Yjq 必须在镜子的同一侧,

包括镜子所在直线上(参见样例 1) 。如果视线与镜子重合, 那

么不会发生反射, 并且镜子不被当作障碍物 (参见样例 4) 。Hja

很想知道他站在原地能否看见 Yjq,帮助他解决这个问题。

【输入格式】

【输出格式】
如果 Hja 站在原地能看到 Yjq,则输出"YES",否则输出"NO"。
【样例输入 1】
-1 3
1 3
0 2 0 4
0 0 0 1
【样例输出 1】
NO
【样例输入 2】
0 0
1 1
0 1 1 0
-100 -100 -101 -101
【样例输出 2】
NO
【样例输入 3】
0 0
1 1
0 1 1 0
-1 1 1 3
【样例输出 3】
YES
【样例输入 4】
0 0
10 0
100 100 101 101
1 0 3 0
【样例输出 4】
YES
【数据规模与约定】
对于100%的数据,所有坐标均为绝对值不超过10 4 的整数。

输入的线段不会退化成点,且两条线段没有交点。Hja 和

Yjq 的位置不同,且不在任何一条线段上。

题解:计算几何 弃疗

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1e-;
int sgn(double a)
{
if (fabs(a)<eps) return ;
else
{
if (a>0.0) return ;
else return -;
}
}
struct point
{
double x,y;
point(){}
point(double a,double b)
{
x=a;y=b;
}
void init()
{
scanf("%lf%lf",&x,&y);
}
point operator+(const point &a)const
{
point ans;
ans.x=x+a.x;
ans.y=y+a.y;
return ans;
}
point operator-(const point &a)const
{
point ans;
ans.x=x-a.x;
ans.y=y-a.y;
return ans;
}
point operator*(const double &a)const
{
point ans;
ans.x=x*a;
ans.y=y*a;
return ans;
}
void print()
{
printf("%lf %lf\n",x,y);
}
}v,p,w1,w2,m1,m2;
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
double dot(point a,point b)
{
return a.x*b.x+a.y*b.y;
}
bool cross(point p1,point p2,point p3,point p4)
{
if (sgn(cross(p2-p1,p3-p1))*sgn(cross(p2-p1,p4-p1))==) return false;
if (sgn(cross(p4-p3,p1-p3))*sgn(cross(p4-p3,p2-p3))==) return false;
if (sgn(max(p1.x,p2.x)-min(p3.x,p4.x))==-) return false;
if (sgn(max(p1.y,p2.y)-min(p3.y,p4.y))==-) return false;
if (sgn(max(p3.x,p4.x)-min(p1.x,p2.x))==-) return false;
if (sgn(max(p3.y,p4.y)-min(p1.y,p2.y))==-) return false;
return true;
}
point getcross(point p1,point p2,point p3,point p4)
{
double a=p2.y-p1.y;
double b=p1.x-p2.x;
double c=-p1.x*p2.y+p1.y*p2.x;
double d=p4.y-p3.y;
double e=p3.x-p4.x;
double f=-p3.x*p4.y+p3.y*p4.x;
double x=(b*f-c*e)/(a*e-b*d);
double y=(a*f-c*d)/(b*d-a*e);
return point(x,y);
}
point calcfoot(point p1,point p2,point p3)
{
double ratio=dot(p1-p2,p3-p2)/dot(p3-p2,p3-p2);
return p2+(p3-p2)*ratio;
}
bool check()
{
if (!cross(v,p,w1,w2))
{
if (!cross(v,p,m1,m2)) return true;
if (sgn(cross(m1-v,m2-v))== && sgn(cross(m1-p,m2-p)==)) return true;
}
if (sgn(cross(m2-m1,v-m1))*sgn(cross(m2-m1,p-m1))==)
{
point foot=calcfoot(p,m1,m2);
foot=foot*2.0-p;
if (cross(v,foot,m1,m2))
{
foot=getcross(v,foot,m1,m2);
if (!cross(v,foot,w1,w2) && !cross(foot,p,w1,w2)) return true;
}
}
return false;
}
int main()
{
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
v.init();
p.init();
w1.init();
w2.init();
m1.init();
m2.init();
if (check()) printf("YES\n");
else printf("NO\n");
return ;
}

AC

c
【问题描述】
你是能看到第三题的 friends 呢。
——aoao
众所周知,八数码问题是一个非常难的问题,但是Yjq 非常有

面子,他把这道题简化了一番。 现在给了你一个3 × 3的方格

图, 你的目标是通过不断移动使得相邻颜色的块形成联通块。

你每次的移动方式是选择一列或者一行进行置换滑动

(这个解释起来比较麻烦,看下面的图就懂了) 。所谓置换滑动,

就是所有格子沿着给定的方向顺次移动, 最后一个格子会被置换

到最前面的过程。 现在给定整个方格图,以及每个格子是否能够

移动,求使得相同颜色联通的最小步数。

【输入格式】
输入为3 × 3的方格图,每个位置由五个字符组成,前四个字符分别

表示上下左右四个部分的颜色, 第五个字符表示该格子是否能够移

动, 其中0是能移动1是不能移动。

【输出格式】
一行一个整数代表答案。

题解:爆搜

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue> using namespace std; #define get(a,b,c) ((a-1)*12+(b-1)*4+c) int en,tmp[][],color[],map[][],q[],nowmap[][],newmap[][]; bool num[],use[],right[],row[],col[],col_find[]; char s[]; struct rec
{
int sta,step;
rec(){}
rec(int a,int b)
{
sta=a;step=b;
}
}; queue<rec> que; struct edge
{
int e;
edge *next;
}*v[],ed[]; void add_edge(int s,int e)
{
en++;
ed[en].next=v[s];v[s]=ed+en;v[s]->e=e;
en++;
ed[en].next=v[e];v[e]=ed+en;v[e]->e=s;
} bool check(int nows)
{
memset(num,false,sizeof(num));
for (int a=;a>=;a--)
for (int b=;b>=;b--)
if (a!= || b!=)
{
tmp[a][b]=nows%;
num[nows%]=true;
nows/=;
}
for (int a=;a<;a++)
if (!num[a])
{
tmp[][]=a;
break;
}
int cnt=;
for (int a=;a<=;a++)
for (int b=;b<=;b++)
for (int c=;c<=;c++)
{
cnt++;
color[cnt]=map[tmp[a][b]][c];
}
memset(right,false,sizeof(right));
memset(col_find,false,sizeof(col_find));
for (int a=;a<=;a++)
if (!right[a])
{
if (col_find[color[a]]) return false;
col_find[color[a]]=true;
int front=,tail=;
q[]=a;
right[a]=true;
for (;front<=tail;)
{
int now=q[front++];
for (edge *e=v[now];e;e=e->next)
if (color[e->e]==color[now] && !right[e->e])
{
right[e->e]=true;
q[++tail]=e->e;
}
}
}
return true;
} int main()
{
freopen("c.in","r",stdin);
freopen("c.out","w",stdout); for (int a=;a<=;a++)
for (int b=;b<=;b++)
{
add_edge(get(a,b,),get(a,b,));
add_edge(get(a,b,),get(a,b,));
add_edge(get(a,b,),get(a,b,));
add_edge(get(a,b,),get(a,b,));
if (a!=) add_edge(get(a,b,),get(a+,b,));
if (b!=) add_edge(get(a,b,),get(a,b+,));
}
int cnt=;
for (int a=;a<=;a++)
for (int b=;b<=;b++)
{
scanf("%s",s+);
for (int c=;c<=;c++)
if (s[c]=='R') map[cnt][c]=;
else
{
if (s[c]=='G') map[cnt][c]=;
else
{
if (s[c]=='B') map[cnt][c]=;
else map[cnt][c]=;
}
}
if (s[]=='') row[a]=col[b]=true;
cnt++;
}
int nows=;
if (check(nows))
{
printf("0\n");
return ;
}
que.push(rec(nows,));
use[nows]=true;
rec now;
while (que.size())
{
now=que.front();
que.pop();
int step=now.step;
int nows=now.sta;
memset(num,false,sizeof(num));
for (int a=;a>=;a--)
for (int b=;b>=;b--)
if (a!= || b!=)
{
nowmap[a][b]=nows%;
num[nows%]=true;
nows/=;
}
for (int a=;a<;a++)
if (!num[a])
{
nowmap[][]=a;
break;
}
int news=;
for (int a=;a<=;a++)
{
if (!row[a])
{
for (int b=;b<=;b++)
for (int c=;c<=;c++)
newmap[b][c]=nowmap[b][c];
int x=newmap[a][];
newmap[a][]=newmap[a][];newmap[a][]=newmap[a][];newmap[a][]=x;
news=;
for (int b=;b<=;b++)
for (int c=;c<=;c++)
if (b!= || c!=) news=news*+newmap[b][c];
if (!use[news])
{
use[news]=true;
if (check(news))
{
printf("%d\n",step+);
return ;
}
que.push(rec(news,step+));
}
x=newmap[a][];
newmap[a][]=newmap[a][];newmap[a][]=newmap[a][];newmap[a][]=x;
news=;
for (int b=;b<=;b++)
for (int c=;c<=;c++)
if (b!= || c!=) news=news*+newmap[b][c];
if (!use[news])
{
use[news]=true;
if (check(news))
{
printf("%d\n",step+);
return ;
}
que.push(rec(news,step+));
}
}
if (!col[a])
{
for (int b=;b<=;b++)
for (int c=;c<=;c++)
newmap[b][c]=nowmap[b][c];
int x=newmap[][a];
newmap[][a]=newmap[][a];newmap[][a]=newmap[][a];newmap[][a]=x;
news=;
for (int b=;b<=;b++)
for (int c=;c<=;c++)
if (b!= || c!=) news=news*+newmap[b][c];
if (!use[news])
{
use[news]=true;
if (check(news))
{
printf("%d\n",step+);
return ;
}
que.push(rec(news,step+));
}
x=newmap[][a];
newmap[][a]=newmap[][a];newmap[][a]=newmap[][a];newmap[][a]=x;
news=;
for (int b=;b<=;b++)
for (int c=;c<=;c++)
if (b!= || c!=) news=news*+newmap[b][c];
if (!use[news])
{
use[news]=true;
if (check(news))
{
printf("%d\n",step+);
return ;
}
que.push(rec(news,step+));
}
}
}
} return ;
}

AC

2017.10.1北京清北综合强化班DAY1的更多相关文章

  1. 2017.10.3北京清北综合强化班DAY3

    括号序列(bracket) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一个括号序列,但这个序列不一定合法. 一个合法的括号序列如下: ()是合法的 ...

  2. 2017.10.4北京清北综合强化班DAY4

    财富(treasure) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以 ...

  3. 2017.10.7北京清北综合强化班DAY7

    1.计数 (count.cpp/c/pas) 时间限制:1s 内存限制:256MB [问题描述] 给出m个数a[1],a[2],…,a[m] 求1~n中有多少数不是a[1],a[2],…,a[m]的倍 ...

  4. 2017.10.6北京清北综合强化班DAY6

    题目大意:改变一个数的位置 把一个序列变成不下降序列 题解: 设置一个pre,如果破坏单调性,就把‘删除’这个.否则把pre修改为当前元素的值. 考试时这样得了90分,是因为我的做法只能过这样的数据 ...

  5. 2017.10.5北京清北综合强化班DAY5

    拼不出的数lost.in/.out/.cpp[问题描述]3 个元素的集合{5, 1,2} 的所有子集的和分别是0,1, 2, 3, 5, 6, 7, 8.发现最小的不能由该集合子集拼出的数字是4.现在 ...

  6. 2017.10.2北京清北综合强化班DAY2

    a[问题描述]你是能看到第一题的 friends呢.                                                —— hja世界上没有什么比卖的这 贵弹丸三还令人绝 ...

  7. 北京清北 综合强化班 Day1

    a [问题描述]你是能看到第一题的 friends呢.                                                         —— hja何大爷对字符串十分有 ...

  8. 北京清北 综合强化班 Day4

    财富(treasure) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以 ...

  9. 北京清北 综合强化班 Day3

    括号序列(bracket) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一个括号序列,但这个序列不一定合法. 一个合法的括号序列如下: ()是合法的 ...

随机推荐

  1. Unity框架入门

    介绍Unity框架之前,先要说几个概念DIP依赖倒置原则.IOC控制反转.DI依赖注入 DIP是设计原则之一,定义:上层不应该依赖于底层,两者都依赖于抽象: 抽象不依赖于细节,细节应该依赖于抽象. 像 ...

  2. GitHub从无到有

    一步一步教你如何在GitHub上上传自己的项目 2018年07月04日 09:23:40 夏雨薇安 阅读数:22764   首先你得注册一个自己的GitHub账号,注册网址:https://githu ...

  3. java jdk和android sdk的安装以及环境变量的配置

    安卓环境变量设置 (烦)http://wenku.baidu.com/link?url=QRwpFhP8d0yJorhcvuZPrz3lNFQW-uwYg6TlZtv6uen6_SVsvRrzf0UJ ...

  4. 第一章 MATLAB数字图像处理编程基础

    1 为什么用MATLAB MATLAB的图像处理工具箱(Image Processing Toolbox,IPT)封装了一系列不同图像处理需求的标准算法,它们都是通过直接或间接调用MATLAB中矩阵运 ...

  5. A norm is a function. 范数是函数。

    [范数]范数是函数.A norm is a function.范数(norm),是具有“长度”概念的函数.在线性代数.泛函分析及相关的数学领域,是一个函数,其为向量空间内的所有向量赋予非零的正长度或大 ...

  6. 使用OpenSSL工具制作X.509证书的方法及其注意事项总结

    版权声明:本文为博主原创文章.转载请注明出处. https://blog.csdn.net/Ping_Fani07/article/details/21622545 怎样使用OpenSSL工具生成根证 ...

  7. MyEclipse2014新增bug,尝鲜的朋友需注意NotFoundException: org.springframework.web.context.ContextLoaderListener

    事实上标题后面加上这个异常信息并不合适,可是为了方便和我遇到相同问题的童鞋搜到这篇文章.我不得不这样写啦. 这个异常和你的程序没有关系,假设你没有忘记增加spring Jar包的话,这是fucking ...

  8. Oracle视图传递参数

    在Oracle里,视图不像存储过程和函数一样,可以定义输入参数,但我们可以变个方式,使用程序包来实现. oracle package: oracle package是oracle包,是一组相关过程.函 ...

  9. C#练习委托、事件、事件处理

    控制台应用程序效果: 代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  10. Arduino 看门狗使用

    1.需要调用 #include <avr/wdt.h> 2.设置看门狗复位时间 wdt_enable(WDTO_2S); 代码时间定义的底层查看 #define WDTO_15MS 0 / ...