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 ...
随机推荐
- 读取web应用下的资源文件(例如properties)
package gz.itcast.b_resource; import java.io.IOException; import java.io.InputStream; import java.ut ...
- java之二叉树--未完待续
参考http://how2j.cn/k/collection/collection-tree/476.html#nowhere 二叉树概念 二叉树由各种节点组成二叉树特点:每个节点都可以有左子节点,右 ...
- C# 生成word 文档 代码 外加 IIS报错解决方案
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- rpm 软件包
rpm 软件包 Linux 中有安装软件方式有两种,源码安装以及软件包安装: 压缩包:源码包,编译后安装 rpm(redhat package manager 红帽软件包管理):需要编译,直接安装 ...
- ABP 软删除ISoftDelete
一.简介 ABP 的软删除是为了,在删除的时候,不是真正的删除数据,是为了保护数据. 二.具体实现 在 Core 层,我们需要这个实体去实现这个 ISoftDelete 接口.实现它的 public ...
- 2014-10-22 NOIP模拟赛
1 1 .传教士 (bishop) 问题描述:panzhili 王国的疆土恰好是一个矩形,为了管理方便,国王 jjs 将整个疆土划分成 N*M 块大小相同的区域.由于 jjs 希望他的子民也能信教爱教 ...
- 【TIDB】3、数据库的发展历史、现在、未来
1.从单机数据库说起(Mysql.Oracle.PostgreSQL) 关系型数据库起源自1970年代,其最基本的功能有两个: 把数据存下来: 满足用户对数据的计算需求. 第一点是最基本的要求,如果一 ...
- hyperledger fabric 1.0.5 分布式部署 (九)
linux 使用vim.ctags 配置fabric 源码阅读环境 首先需要安装 ctags,作者使用apt-get 来安装的,安装的版本是5.9 apt-get install ctags 5.9 ...
- Continuous Integration
https://dzone.com/articles/continuous-delivery-toolchain
- 洛谷 P3381 【模板】最小费用最大流
题目描述 如题,给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 输入输出格式 输入格式: 第一行包含四个正整数\(N.M.S.T\) ...