Codeforces_842
A.枚举一个区间,判断是否有数符合。
#include<bits/stdc++.h>
using namespace std; long long l,r,x,y,k; int main()
{
ios::sync_with_stdio();
cin >> l >> r >> x >> y >> k;
for(int i = x;i <= y;i++)
{
if(l <= i*k && i*k <= r)
{
cout << "YES" << endl;
return ;
}
}
cout << "NO" << endl;
return ;
}
B.判断两个边界。
#include<bits/stdc++.h>
using namespace std; int r,d,n; int main()
{
ios::sync_with_stdio();
cin >> r >> d >> n;
int ans = ;
for(int i = ;i <= n;i++)
{
double x,y,rr;
cin >> x >> y >> rr;
double dis = sqrt(x*x+y*y);
if(dis-rr > r-d-1e- && dis+rr < r+1e-) ans++;
}
cout << ans << endl;
return ;
}
C.暴力判断每种gcd,set去重后实际的数量很少。
#include<bits/stdc++.h>
using namespace std; int n,a[],ans[] = {};
vector<int> v[];
set<int> s[]; void dfs(int now,int pre)
{
for(int t : s[pre]) s[now].insert(__gcd(t,a[now]));
a[now] = __gcd(a[pre],a[now]);
s[now].insert(a[pre]);
for(int t : s[now]) ans[now] = max(ans[now],t);
for(int t : v[now])
{
if(t == pre) continue;
dfs(t,now);
}
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i < n;i++)
{
int x,y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
a[] = ;
s[].insert();
dfs(,);
for(int i = ;i <= n;i++) cout << ans[i] << " ";
cout << endl;
return ;
}
D.前缀和,二分判断每一位,还要记录位置改变状态。
#include<bits/stdc++.h>
using namespace std; int n,m,cnt[] = {}; int main()
{
ios::sync_with_stdio();
cin >> n >> m;
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
cnt[x] = ;
}
for(int i = ;i <= ;i++) cnt[i] += cnt[i-];
int t = ;
while(m--)
{
int z;
cin >> z;
t ^= z;
int l = ,r = (<<)-;
for(int i = ;i >= ;i--)
{
int tt = t&(<<i),mid = (l+r)/;
if(tt)
{
if(cnt[r]-cnt[mid] < r-mid) l = mid+;
else r = mid;
}
else
{
if(cnt[mid]-(l?cnt[l-]:) < mid-l+) r = mid;
else l = mid+;
}
}
cout << (l^t) << endl;
}
return ;
}
Codeforces_842的更多相关文章
随机推荐
- spring boot 中AOP的使用
一.AOP统一处理请求日志 也谈AOP 1.AOP是一种编程范式 2.与语言无关,是一种程序设计思想 面向切面(AOP)Aspect Oriented Programming 面向对象(OOP)Obj ...
- 在EasyUI项目中使用FileBox控件实现文件上传处理
我在较早之前的随笔<基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用>Web框架介绍中介绍了基于Uploadify的文件上传操作,免费版本用的是J ...
- 深度学习论文翻译解析(六):MobileNets:Efficient Convolutional Neural Networks for Mobile Vision Appliications
论文标题:MobileNets:Efficient Convolutional Neural Networks for Mobile Vision Appliications 论文作者:Andrew ...
- 你对Java泛型的理解够深入吗?
泛型 泛型提供了一种将集合类型传达给编译器的方法,一旦编译器知道了集合元素的类型,编译器就可以对其类型进行检查,做类型约束. 在没有泛型之前: /** * 迭代 Collection ,注意 Coll ...
- Anaconda----Python的计算环境
由于要用到opencv中的cv2这个module,我会在Anaconda这个Python的计算环境中安装加入opencv. 打开一个终端,输入: conda install opencv 显示: 选择 ...
- linux修改环境变量的三种方法【转】
[环境变量配置的三个方法] 如想将一个路径加入到$PATH中,可以像下面这样做: 1. 控制台中,不赞成使用这种方法,因为换个shell,你的设置就无效了,因此这种方法仅仅是临时使用,以后要使用的时 ...
- Scanner使用方法
import java.util.Scanner; //导入包 public void main (String args[]){ Scanner a=new Scanner(System.in); ...
- cogs 1298. 通讯问题 Tarjan
1298. 通讯问题 ★★ 输入文件:jdltt.in 输出文件:jdltt.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员,每个队员 ...
- hdu - 4965
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...
- 如何优雅的用策略模式,取代臃肿的 if-else 嵌套,看这篇就够了
经常听同事抱怨,订单来源又加了一种,代码又要加一层if-else判断,光判断订单来源的if-else就好几百行代码,代码我都不想看了,相信很多同行都有过这样的感受! Java的二十几种设计模式背的滚瓜 ...