Codeforces Round #613 (Div. 2) (A-E)
A略


直接求和最大的子序列即可(注意不能全部选中整个子序列)
or

#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
vector<int> a(n);
vector<long long> sum(n+1,0);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
sum[i]=sum[i-1]+a[i-1];
long long mx=-1e18;
int val=0;
for(int i=1;i<=n;i++){
if(i==n&&val==0) continue;
mx=max(mx,sum[i]-sum[val]);
if(sum[i]<=sum[val]) val=i;
}
if(mx>=sum[n]) puts("NO");
else puts("YES");
}
int main(){
int t;
cin>>t;
while(t--)
solve();
}

设X的素因子分解式为 p1^c1*p2^c2*p3^c3...,且lcm(a,b)=X

或者也可以利用二进制来枚举
二进制枚举的方法(来自官方题解)
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long ll x; int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> x;
vector <ll> f;
for(ll i = 2 ; i * i <= x ; i++){
if(x % i == 0){
ll cur = 1;
while(x % i == 0){
x /= i;
cur *= i;
}
f.push_back(cur);
}
}
if(x > 1) f.push_back(x);
int n = f.size();
ll ansa = 1e18, ansb = 1e18;
for(int i = 0 ; i < (1 << n) ; i++){
ll a = 1, b = 1;
for(int j = 0 ; j < n ; j++){
if((i >> j) & 1) a *= f[j];
else b *= f[j];
}
if(max(a, b) < max(ansa, ansb)){
ansa = a;
ansb = b;
}
}
cout << ansa << " " << ansb << endl;
}
枚举因子
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x;
cin>>x;
long long ans=1;
for(long long i=2;i*i<=x;i++){
if(x%i==0){
if(__gcd(i,x/i)==1) {
ans=i;
}
}
}
cout<<ans<<' '<<x/ans<<endl;
}

不难想,主要是代码写法,做法参考官方题解

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int solve(vector<int>& c,int dep){
if(c.size()==0||dep<0) return 0;
vector<int> l,r;
for(auto i:c){
if(((i>>dep)&1)==0) l.push_back(i);
else r.push_back(i);
}
if(l.size()==0) return solve(r,dep-1);
if(r.size()==0) return solve(l,dep-1);
return min(solve(l,dep-1),solve(r,dep-1))+(1<<dep);
}
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
cout<<solve(a,30);
}


首先是由计数不同区间改为计数区间的左端点个数
然后利用扫描线算法将原始区间排序,然后开始遍历

我们首先枚举到的是1的左端点,我们存下他(用set就好),然后到达2的左端点,此时发现2被一个区间覆盖,就是被区间1,因此删除掉区间1会导致增加一个新的左端点,也就是区间2的左端点,
因此我们让ans[1]++,然后将区间2加进set,之后2的右端点,set删除2,又到了4的左端点,发现删除区间又会导致增加一个新的左端点,因此ans[1]++,之后将区间4加进set,
然后到达区间3的左端点,此时set中有两个,也就是说我们不管删除set中的哪一个都不会导致增加新的左端点,所以ans不变,将3加进去即可
这样做只是计算了删除掉这个区间之后增加了多少新的左端点,因此还需要计算删除掉这个区间之后会不会导致失去左端点,这个就很简单了,不废话了
#include<bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); i++)
#define fore(i, s, t) for (int i = s; i < (int)t; i++)
#define fi first
#define se second using namespace std; const int maxn=2e5+5; typedef pair<int,int> pi; const int inf=2e9; map<int,int> ls; int get(vector<pi> a){
int cnt=0;
int l=-inf,r=-inf;
sort(a.begin(),a.end());
for(int i=0;i<a.size();i++){
if(a[i].fi>r) {
if(r!=-inf) ls[l]=0;
++cnt;
l=a[i].fi,r=a[i].se;
}
else r=max(r,a[i].se);
}
ls[l]=0;
return cnt;
} void process(vector<pair<int,pi>>& qr,vector<int>& ans){
set<int> now;
forn(i,qr.size()){
vector<int> tl,tr;
int j=i-1;
while(j+1<qr.size()&&qr[j+1].fi==qr[i].fi){
j++;
if(qr[j].se.fi==1) tl.push_back(qr[j].se.se);
else tr.push_back(qr[j].se.se);
}
if(now.size()==1&&tl.size()) ++ans[*now.begin()];
for(int it:tl) now.insert(it);
for(int it:tr) now.erase(it);
i=j;
}
} void solve(){
int n;
cin>>n;
vector<pi> a(n);
for(int i=0;i<n;i++){
scanf("%d%d",&a[i].fi,&a[i].se);
}
vector<pair<int,pi>>qr;
for(int i=0;i<n;i++){
qr.push_back({a[i].fi,{1,i}});
qr.push_back({a[i].se,{-1,i}});
}
sort(qr.begin(),qr.end());
ls.clear();
int cur=get(a);
vector<int> ans(n,0);
process(qr,ans);
forn(i,n) if(ls.count(a[i].fi)) ++ls[a[i].fi];
forn(i,n) if(ls[a[i].fi]==1) --ans[i];
printf("%d\n",*max_element(ans.begin(),ans.end())+cur);
}
int main(){
int n;
cin>>n;
forn(i,n) solve();
}
Codeforces Round #613 (Div. 2) (A-E)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
随机推荐
- [C/C++]const限定符总结
const限定符 const是一种限定符,被const所限定的变量其值不可以被改变. const的初始化 由于const一旦创建其值就不能够被改变,所以我们必须对其进行初始化 const int a; ...
- java8种基本数据类型
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 20191223-python学习第三天
1.运算符补充 (1)in 与 not in 学习 (2)优先级 >小于 ,<小于,计算运算关系优先级 > not > and > or 2.charm自动生成文件头部 ...
- python 实现 跳一跳游戏 代码解析
这个代码实现的是 手动点击起点 和 终点 ,程序自动判断距离.触屏时间 完成跳跃 原理(摘自项目说明页面):1. 将手机点击到“跳一跳”小程序界面:2. 用Adb 工具获取当前手机截图,并用a ...
- 维基逃离MySQL 力挺开源数据库 MariaDB
近日全球著名百科类网站维基百科宣布,将不会再用MySQL数据库,据国外媒体报道,很多年,MySQL一直是热门的开源数据库,不过在被甲骨文收购后,面临闭源的风险.因此维基百科将切换到另外一款开源数据库M ...
- To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
mongoose报错:DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and wil ...
- mac 软件相关的
mac 系统教学 https://www.w3cschool.cn/macdevsetup/carp1i83.html 可以查看的软件网站 https://www.ifunmac.com/ https ...
- 子组件获取父组件数据 propsDown, 父组件获取子组件数据 eventUp
(一) popsDowm 三种方法获取父组件数据:被动获得(1):主动获取(2). 1.被动获得: 父组件:v-bind: 绑定变量参数和方法参数:子组件:props 接收参数.可以在模板中直接使用也 ...
- dict的使用
Python字典是可变类型数据,可以存储任意对象,如字符串,数字,元组,列表等. 字典的创键 字典有键key和值value组成,使用键值对链接:,字典也称为关联数组或哈希表. dict_person ...