2017.10.1 QBXT 模拟赛
T1
枚举右端点,前缀和优化。对于当前点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>
#define N 1000500
char s[N];
int n,last[],sum[],pr[][],minv[][];
int max(int a,int b){return a>b?a:b;}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
scanf("%d%s",&n,s+);
int ans=;
for(int j=;j<=n;++j)
{
int p=s[j]-'a';
sum[p]++;
last[p]=j;
for(int i=;i<=;++i)
{
if(sum[i]&&i!=j) ans=max(ans,sum[i]-sum[p]-minv[i][p]-(last[i]==pr[i][p])),
ans=max(ans,sum[p]-sum[i]-minv[p][i]-(last[i]==pr[p][i]));
}
for(int i=;i<=;++i)
{
if(sum[i]-sum[p]<minv[i][p]) minv[i][p]=sum[i]-sum[p],pr[i][p]=j;
if(sum[p]-sum[i]<minv[p][i]) minv[p][i]=sum[p]-sum[i],pr[p][i]=j;
}
}
printf("%d\n",ans);
return ;
}
T2
计算几何
判断两条直线是否相交
如果两个人连线与墙相交的话 一定是NO
如果两个人分布在墙一侧 我们可以用对称找到一个点在墙另一边的对称点
这样就成了在墙的两侧 判断连线是否与墙相交
这个题它还是线段。
所以不能只找交点,还需要判断交点是否在线段上
#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 ;
}
T3
怀疑人生的BFS
#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 ;
}
2017.10.1 QBXT 模拟赛的更多相关文章
- 2017.10.7 QBXT 模拟赛
题目链接 T1 容斥原理,根据奇偶性进行加减 #include<iostream> #include<cstdio> using namespace std; typedef ...
- 2017.10.3 QBXT 模拟赛
题目链接 T1 模拟 #include <cstring> #include <cstdio> #define N 105000 int L,R; char s[N]; int ...
- 2017.10.6 QBXT 模拟赛
题目链接 T1 Sort 一下与原数组比较 ,若有两个数或者没有数发生位置交换 ,则输出YES ,否则输出NO #include <algorithm> #include <ccty ...
- 2017.10.5 QBXT 模拟赛
题目链接 T1 从小到大排序,用sum记录前缀和,然后枚举1~n个数 ,如果当前的前缀和 + 1小于a[i]的话 那么 sum + 1永远不可能拼出来 直接输出sum + 1 ,否则统计前缀和.最后如 ...
- 2017.10.4 QBXT 模拟赛
题目链接 T1 维护一个单调栈 #include <iostream> #include <cstdio> #define N 500000 #define rep(a,b,c ...
- 2017.10.2 QBXT 模拟赛
题目链接 T1 我们所要求得是(a*b)|x 也就是 使(a*b)的倍数小于x的个数之和 1<=x<=n 我们可以 找一个c使得 (a*b*c)<=x 由于我们所求的是一个三元有序对 ...
- 2017 10.25 NOIP模拟赛
期望得分:100+40+100=240 实际得分:50+40+20=110 T1 start取了min没有用,w(゚Д゚)w O(≧口≦)O T3 代码3个bug :数组开小了,一个细节没注意, ...
- 2017.10.28 QB模拟赛 —— 下午
题目链接 T1 按x值排序 遇到第二种牌插入 遇到第一种牌 查询<=y 的最小值 删除他 splay multiset cys大佬说 multiset就是不去重的set, #include &l ...
- 2017.10.28 QB模拟赛 —— 上午
题目链接 T1 1e18 内的立方数有 1e6个 直接枚举可过 二分最优 考场用set 死慢.. #include <cstdio> int t; long long p; int ma ...
随机推荐
- iptable学习
参考文档 朱双印个人日志 netfilter/iptables架构 位置 钩子函数/规则链 说明 数据包刚刚进入网络层的位置 PREROUTING 在这里处理目标地址转换 经过路由判断,数据包从内核流 ...
- 【并发编程】一文带你读懂深入理解Java内存模型(面试必备)
并发编程这一块内容,是高级资深工程师必备知识点,25K起如果不懂并发编程,那基本到顶.但是并发编程内容庞杂,如何系统学习?本专题将会系统讲解并发编程的所有知识点,包括但不限于: 线程通信机制,深入JM ...
- IT兄弟连 JavaWeb教程 过滤器1
Servlet过滤器是从Servlet2.3规范开始新增的功能,并在Servlet2.4规范中得到增强,监听器可以监听到Web应用程序启动和关闭.创建过滤器和监听器需要继承相应接口,并对其进行配置. ...
- 截取HTML中的JSON数据并利用GSON进行解析(Android)
截取HTML中的JSON数据并利用GSON进行解析(Android) 前言 最近在做的一个Android项目,需要自行搭建服务器,队友选择买了阿里云的服务器ESC产品,在数据获取上,我们采用了Andr ...
- Java无模板导出Excel,Apache-POI插件实现
开发环境 jdk 1.8 Maven 3.6 Tomcat 8.5 SpringBoot 2.1.4.RELEASE Apache-POI 3.6 Idea 注意: 我是在现有的基于SpringBoo ...
- HDMI和VGA接口
HDMI英文全称为:High Definition Multimedia Interface,它是一种全数字化视频和声音发送接口,可以发送未压缩的音频及视频信号. HDMI接口与VGA接口区别如下: ...
- Glassfish Cannot run program "/usr/libexec/StartupItemContext; error=2 , No such file or directory
临时处理办法 http://sohu.io/questions/3833214/jvm-failed-to-start-java-io-ioexception-cannot-run-program-u ...
- thinkphp5实现mysql数据库还原
数据库还原其实就是从.sql文件中读取一行一行的命令,然后执行 需要配置数据库文件database.php,数据库名,主机名,用户名,密码这里就不说了,这里说的要配置数据库连接参数 'params' ...
- 黑马Mybatis day3 多表查询 1.xml配置方式 2.注解方式
package com.itheima.mozq; import com.itheima.domain.Order; import com.itheima.mapper.OrderMapper; im ...
- VUE图片懒加载-vue lazyload插件的简单上手使用(优化版本)
在用VUE做项目开发的过程中,首页用到了懒加载的方法,查找了一些方法,觉得官网写得太复杂,有一篇博客不错(https://www.cnblogs.com/xyyt/p/7650539.html),但是 ...