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 ...
随机推荐
- Sharepoint2013搜索学习笔记之设置业务数据内容源(六)
Sharepoint搜索爬网组件支持爬Business Data Connectivity Service 承载的外部数据,关于Business Data Connectivity Service设置 ...
- PHP注释-----PHPDOC
用过IDE或看过其他源码的小伙伴们应该都见过类似下面这样的注释 /** * 递归获取所有游戏分类 * @param int $id * @return array */ 看得多了就大概知道了一些规 ...
- ubuntu18.04安装opencv 3.4.1
github 地址: https://github.com/opencv/opencv 安装依赖 sudo apt-get install build-essential sudo apt--dev ...
- h5模型文件转换成pb模型文件
本文主要记录Keras训练得到的.h5模型文件转换成TensorFlow的.pb文件 #*-coding:utf-8-* """ 将keras的.h5的模型文件,转换 ...
- Unity3d导入3dmax后model 的缩放为0.0254的原因以及解决办法
http://blog.csdn.net/pdw_jsp/article/details/51259493 这个问题其实已经早都出现过了,今天我们这边也碰到了,这里做个记录吧 导致的问题~ 场景的比例 ...
- UE4中资源加载资源的方式
在UNITY中,我们加载资源一般是通过Resources.Load(path).即可完成.该方法返回的是Object类型.如果你想要的是材质或者贴图等等,只要价格类型转换的关键字就可以了例如 as M ...
- C 语言实例 - 求两数最小公倍数
C 语言实例 - 求两数最小公倍数 用户输入两个数,其这两个数的最小公倍数. 实例 - 使用 while 和 if #include <stdio.h> int main() { int ...
- 微信小程序采坑之上拉触底加载更多和下拉刷新
小程序中加载更多数据一般都是触底刷新 有自带的函数: onReachBottom: function (){} 但是在使用时触发完全没有反应,后来尝试给外层加了一个高度,解决问题 仔细想想也是,没有设 ...
- JS高级学习历程-12
冒充继承 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/T ...
- [題解](函數下整點個數?)luogu_P4132_BZOJ_2659_算不出的等式
兩個都是一次函數,下取整就是整點個數,兩個函數k剛好成倒數,所以最後發現會組合成一個矩形 (為啥要考慮重複與否的問題???) 然而這樣會不會重複計算點數呢 我們發現因為取的是圖像下的整數點 所以要想重 ...