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 ;
}

最新文章

  1. jQuery入门第二天&amp;&amp;&amp;正则表达式完结篇——仿smarty引擎的制作
  2. Android开发环境的调研
  3. Asp.net Vnext ModelBinding
  4. BufferedInputStream/BufferedOutputStream复制文件
  5. 黄聪:PHP json_encode中文乱码解决方法
  6. AFNetworking使用
  7. ACM——A + B Problem (2)
  8. App自动更新之通知栏下载
  9. [FindBugs分析记录]Class defines clone() but doesn&#39;t implement Cloneable
  10. 内核模块加载错误 “Invalid module format” 解决办法
  11. 其它综合-CentOS7 忘记root密码
  12. 【webpack】-- 入门与解析
  13. javascript基础的查缺补漏
  14. 转《canvas实现滤镜效果》
  15. CNN做序列标注问题(tensorflow)
  16. [No0000132]正确使用密码加盐散列[译]
  17. Django MTV simple_tag filter inclusion_tag
  18. Mac下安装社区版MongoDB
  19. Android实现Material Design风格的设置页面(滑动开关控件)
  20. SVN 定时 更新代码 Demo

热门文章

  1. 19.python中os模块的常见用法
  2. js面试题之手写节流函数和防抖函数
  3. MySQL数据库保存emoji表情
  4. 【记】VirtualBox安装CentOS6
  5. JPQ整合Querydsl入门篇
  6. 贪心 + DFS
  7. NPOI导出Excel生成多个sheet
  8. python认识及环境变量
  9. 2020寒假学习01 Scala 编程初级实践
  10. 【WPF学习】第十九章 控件类