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 ...
随机推荐
- c程序十六进制字符串转换为整数与反转
字符串转整数使用sscanf ; char *buf = "1d5ce"; sscanf (buf, "%x", &value); printf (&q ...
- minihttp安装配置ssl和c语言实现cgi
概述:参考了大牛们的方法,结合自己的环境做了修改,主要是讲:minihttp安装配置ssl和c语言实现cgi接收字符串并且保存系统环境:centos6.5 开发版 依赖软件包: mini_httpd- ...
- ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)
Transport Ship 25.78% 1000ms 65536K There are NN different kinds of transport ships on the port. T ...
- 在UI程序设计中使用BackgroundWorker进行多线程异步处
WinForm的应用程序中如果执行了一个的非常冗长的处理操作,(比如文件检索,大运算量计算),在执行时就会锁定用户界面,虽然主活动窗口还在运行,但用户无法与程序交互,无法移动窗体或改变窗体大小,导致程 ...
- SCUT - 157 - CC和他的GCD - 容斥原理
https://scut.online/p/157 鉴于多年(都没几个月)搞数论的经验,这种时候枚举g肯定是对的. 那么肯定是要莫比乌斯函数作为因子,因为很显然? 但是为什么要搞个负的呢?其实是因为这 ...
- 关于define
<?php define('local','localhost');//echo constant('local');exit(); define('username','root'); def ...
- 为什么要用babel-polyfill
1.为什么要用babel-polyfill Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如 Iterator.Generator.Set.Maps.Prox ...
- (function (window, document, undefined) {})(window, document)什么意思?
1.IIFE(即时调用的函数表达式),它采取以下表达式: (function (window, document, undefined) { // })(window, document); Java ...
- 安装wepack
安装webpack之前要安装node.js 1.安装webpack运行 npm install webpack -g 和npm install webpack-cli -g npm install w ...
- 剑指Offer的学习笔记(C#篇)-- 跳台阶
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 一 . 解题思路. 由题目可知,青蛙一次可以跳一阶或者两阶.假设台阶为 ...