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的更多相关文章
随机推荐
- Quartz.NET总结(八)如何根据自己需要配置Topshelf 服务
前面讲了如何使用Topshelf 快速开发windows服务, 不清楚的可以看之前的这篇文章:https://www.cnblogs.com/zhangweizhong/category/771057 ...
- JavaScript中函数式编程中文翻译
JavaScript 中的函数式编程 原著由 Dan Mantyla 编写 近几年来,随着 Haskell.Scala.Clojure 等学院派原生支持函数式编程的偏门语言越来越受到关注,同时主流的 ...
- 《图解机器学习-杉山将著》读书笔记---CH1
CH1 什么是机器学习 重点提炼 机器学习的种类: 常分为:监督学习.无监督学习.强化学习等 监督学习是学生从老师那获得知识,老师提供对错指示 无监督学习是在没有老师的情况下,学生自习 强化学习是在没 ...
- POJ 2456 Aggressive cows (二分)
题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...
- ArcGIS Desktop直连PostgreSQL安装及配置图解(windows)
目录 1 PostgreSQL 11.0安装及配置 2 psqlODBC安装及配置 3 PostGIS安装及配置 4 pgAdmin4使用入门 5 空间数据导入 5.1 将PostgreSQL的bin ...
- 你的应用安全吗? ——用Xray和Synk保驾护航
一.背景 在当下软件应用的开发过程当中,自研的内部代码所占的比例逐步地减少,开源的框架和共用库已经得到了广泛的引用.如下图所示,在一个Kubernetes部署的应用当中,我们自己开发代码所占的比例可能 ...
- cogs 2450. 距离 树链剖分求LCA最近公共祖先 快速求树上两点距离 详细讲解 带注释!
2450. 距离 ★★ 输入文件:distance.in 输出文件:distance.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 在一个村子里有N个房子,一 ...
- cogs 3008. 朋友圈
3008. 朋友圈 ★★ 输入文件:friendscircle.in 输出文件:friendscircle.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] NO ...
- mysql高级复习
MySQL官方对索引的定义为:索引(Index)是帮助MySQL高效获取数据的数据结构.可以得到索引的本质:索引是数据结构,可以简单理解为“排好序的快速查找数据结构”. 数据本身之外,数据库还维护着一 ...
- 20190925Java课堂记录(一)
判断字符串是否回文 设计思想 利用递归,每次返回长度减二的字符串,最终返回结果 源程序代码 import java.util.Scanner; public class palindrome { st ...