Codeforces_817
A.要求坐标差为移动距离的两倍。
#include<bits/stdc++.h>
using namespace std; int main()
{
ios::sync_with_stdio();
int x1,x2,y1,y2,x,y;
cin >> x1 >> y1 >> x2 >> y2 >> x >> y;
int xx = abs(x1-x2),yy = abs(y1-y2);
if(xx%x || yy%y)
{
cout << "NO" << endl;
return ;
}
if(xx/x% == yy/y%) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
B.分4种情况分别计算。
#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
sort(a+,a++n);
int num = ,cnt = ;
if(a[] != a[]) num++;
if(a[] != a[]) num++;
if(num == )
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << (long long)cnt*(cnt-)*(cnt-)/ << endl;
}
else if(num == && a[] != a[])
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << (long long)cnt*(cnt-)/ << endl;
}
else
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << cnt << endl;
}
return ;
}
C.若x符合,则x+1肯定符合,可以二分最小的x。
#include<bits/stdc++.h>
using namespace std; long long n,s; bool ok(long long x)
{
long long t = x;
while(t)
{
x -= t%;
t /= ;
}
if(x >= s) return ;
return ;
} int main()
{
ios::sync_with_stdio();
cin >> n >> s;
long long l = ,r = n+;
while(l < r)
{
long long mid = (l+r)/;
if(ok(mid)) r = mid;
else l = mid+;
}
cout << n-l+ << endl;
return ;
}
D.l[i]表示i坐标第一个大于等于a[i]的位置,r[i]表示r右边第一个大于a[i]的位置,这样a[i]被当作max算的次数可以求出。减min只要把每个位置的数取负做相同操作。
#include<bits/stdc++.h>
using namespace std; int n,a[],l[],r[];
long long ans = ; void f()
{
for(int i = ;i <= n;i++)
{
l[i] = i-;
while(l[i] >= && a[i] > a[l[i]]) l[i] = l[l[i]];
}
for(int i = n;i >= ;i--)
{
r[i] = i+;
while(r[i] <= n && a[i] >= a[r[i]]) r[i] = r[r[i]];
}
for(int i = ;i <= n;i++)
ans += (long long)(r[i]-i)*(i-l[i])*a[i];
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
f();
for(int i = ;i <= n;i++) a[i] = -a[i];
f();
cout << ans << endl;
return ;
}
E.01异或trie树,把每个数按位分。
#include<bits/stdc++.h>
using namespace std; int n,tr[][] = {},cnt[],sz = ; void add(int x,int v)
{
int now = ;
for(int i = ;i >= ;i--)
{
int t = bool((<<i)&x);
if(!tr[now][t]) tr[now][t] = ++sz;
now = tr[now][t];
cnt[now] += v;
}
} int getsum(int x,int y)
{
int now = ,ans = ;
for(int i = ;i >= ;i--)
{
int xt = bool((<<i)&x),yt = bool((<<i)&y);
if(!yt && !tr[now][xt]) break;
if(!yt) now = tr[now][xt];
else
{
if(tr[now][xt]) ans += cnt[tr[now][xt]];
if(!tr[now][!xt]) break;
now = tr[now][!xt];
}
}
return ans;
} int main()
{
ios::sync_with_stdio();
cin >> n;
while(n--)
{
int x,y,z;
cin >> x >> y;
if(x == ) add(y,);
else if(x == ) add(y,-);
else
{
cin >> z;
cout << getsum(y,z) << endl;
}
}
return ;
}
Codeforces_817的更多相关文章
随机推荐
- 物理ceph集群+K8s
前提条件 在Ceph为k8s创建一个pool ceph osd pool create k8s 128 创建admin用户 ceph auth get-or-create client.admin m ...
- (一)Django项目架构介绍
项目的架构为: 1.虚拟环境virtualenv 安装Django==2.1.3 安装pymysql 安装mysqlclient 安装其他等 2.项目结构为: 应用APP: blog -- 管理博客 ...
- 原生javascript 基础动画原理
一.实现原理: 1.开定时器前先清除定时器 2.设置定时器 3.当前元素的位置 + 每一步的长度 4.当元素当前位置超过目标点时,把当前位置==目标点 5.设置元素位置,开始运动 6.判断当前位置如果 ...
- Spring--2.Spring之IOC--了解IOC容器
IOC(容器),用来集成别的框架 1.IOC(Inversion(反转)Of Control):控制反转 控制:资源的获取方式: 主动式: BookServlet{ BookService bs=ne ...
- vscode中nodejs智能提示
简单粗暴,直接在项目中,运行npm install --save-dev @types/node命令,然后就ok了.
- 关于neo4j初入门(4)
关于admin管理员 数据库备份和恢复 Neo4j数据库备份 步骤1 -点击“Neo4j Community”,如下图所示 Windows“开始”按钮>> "All Progra ...
- restframework 解析器、渲染器、url控制组件
一.解析器 解析器的作用就是服务端接收客户端传过来的数据,把数据解析成自己可以处理的数据.本质就是对请求体中的数据进行解析. 1.分类 from rest_framework.parsers impo ...
- SEVERE: Unable to process Jar entry [avassist xxxx.class]
<bean id="sqlSessionTemplate2" class="org.mybatis.spring.SqlSessionTemplate" ...
- .net core webapi搭建(2)跨域
Core WebAPI中的跨域处理 在使用WebAPI项目的时候基本上都会用到跨域处理 Core WebAPI的项目中自带了跨域Cors的处理,不需要单独添加程序包 如图所示 修改 Configure ...
- NOI4.6 最小新整数——切山游戏
描述 给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0.n的位数为m. 现在从m位中删除k位(0<k < m),求生成的新整数最小为多少? ...