A略

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

or

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void solve(){
  6. int n;
  7. cin>>n;
  8. vector<int> a(n);
  9. vector<long long> sum(n+1,0);
  10. for(int i=0;i<n;i++)
  11. scanf("%d",&a[i]);
  12. for(int i=1;i<=n;i++)
  13. sum[i]=sum[i-1]+a[i-1];
  14. long long mx=-1e18;
  15. int val=0;
  16. for(int i=1;i<=n;i++){
  17. if(i==n&&val==0) continue;
  18. mx=max(mx,sum[i]-sum[val]);
  19. if(sum[i]<=sum[val]) val=i;
  20. }
  21. if(mx>=sum[n]) puts("NO");
  22. else puts("YES");
  23. }
  24.  
  25. int main(){
  26. int t;
  27. cin>>t;
  28. while(t--)
  29. solve();
  30. }

  

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

或者也可以利用二进制来枚举

二进制枚举的方法(来自官方题解)

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define finish(x) return cout << x << endl, 0
  4. #define ll long long
  5.  
  6. ll x;
  7.  
  8. int main(){
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0);
  11. cin >> x;
  12. vector <ll> f;
  13. for(ll i = 2 ; i * i <= x ; i++){
  14. if(x % i == 0){
  15. ll cur = 1;
  16. while(x % i == 0){
  17. x /= i;
  18. cur *= i;
  19. }
  20. f.push_back(cur);
  21. }
  22. }
  23. if(x > 1) f.push_back(x);
  24. int n = f.size();
  25. ll ansa = 1e18, ansb = 1e18;
  26. for(int i = 0 ; i < (1 << n) ; i++){
  27. ll a = 1, b = 1;
  28. for(int j = 0 ; j < n ; j++){
  29. if((i >> j) & 1) a *= f[j];
  30. else b *= f[j];
  31. }
  32. if(max(a, b) < max(ansa, ansb)){
  33. ansa = a;
  34. ansb = b;
  35. }
  36. }
  37. cout << ansa << " " << ansb << endl;
  38. }

 枚举因子

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. long long x;
  7. cin>>x;
  8. long long ans=1;
  9. for(long long i=2;i*i<=x;i++){
  10. if(x%i==0){
  11. if(__gcd(i,x/i)==1) {
  12. ans=i;
  13. }
  14. }
  15. }
  16. cout<<ans<<' '<<x/ans<<endl;
  17. }

  

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

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn=1e5+5;
  6.  
  7. int solve(vector<int>& c,int dep){
  8. if(c.size()==0||dep<0) return 0;
  9. vector<int> l,r;
  10. for(auto i:c){
  11. if(((i>>dep)&1)==0) l.push_back(i);
  12. else r.push_back(i);
  13. }
  14. if(l.size()==0) return solve(r,dep-1);
  15. if(r.size()==0) return solve(l,dep-1);
  16. return min(solve(l,dep-1),solve(r,dep-1))+(1<<dep);
  17. }
  18.  
  19. int main(){
  20. int n;
  21. cin>>n;
  22. vector<int> a(n);
  23. for(int i=0;i<n;i++)
  24. scanf("%d",&a[i]);
  25. cout<<solve(a,30);
  26.  
  27. }
  28.  

  

首先是由计数不同区间改为计数区间的左端点个数

然后利用扫描线算法将原始区间排序,然后开始遍历

我们首先枚举到的是1的左端点,我们存下他(用set就好),然后到达2的左端点,此时发现2被一个区间覆盖,就是被区间1,因此删除掉区间1会导致增加一个新的左端点,也就是区间2的左端点,

因此我们让ans[1]++,然后将区间2加进set,之后2的右端点,set删除2,又到了4的左端点,发现删除区间又会导致增加一个新的左端点,因此ans[1]++,之后将区间4加进set,

然后到达区间3的左端点,此时set中有两个,也就是说我们不管删除set中的哪一个都不会导致增加新的左端点,所以ans不变,将3加进去即可

这样做只是计算了删除掉这个区间之后增加了多少新的左端点,因此还需要计算删除掉这个区间之后会不会导致失去左端点,这个就很简单了,不废话了

  1. #include<bits/stdc++.h>
  2.  
  3. #define forn(i, n) for (int i = 0; i < int(n); i++)
  4. #define fore(i, s, t) for (int i = s; i < (int)t; i++)
  5. #define fi first
  6. #define se second
  7.  
  8. using namespace std;
  9.  
  10. const int maxn=2e5+5;
  11.  
  12. typedef pair<int,int> pi;
  13.  
  14. const int inf=2e9;
  15.  
  16. map<int,int> ls;
  17.  
  18. int get(vector<pi> a){
  19. int cnt=0;
  20. int l=-inf,r=-inf;
  21. sort(a.begin(),a.end());
  22. for(int i=0;i<a.size();i++){
  23. if(a[i].fi>r) {
  24. if(r!=-inf) ls[l]=0;
  25. ++cnt;
  26. l=a[i].fi,r=a[i].se;
  27. }
  28. else r=max(r,a[i].se);
  29. }
  30. ls[l]=0;
  31. return cnt;
  32. }
  33.  
  34. void process(vector<pair<int,pi>>& qr,vector<int>& ans){
  35. set<int> now;
  36. forn(i,qr.size()){
  37. vector<int> tl,tr;
  38. int j=i-1;
  39. while(j+1<qr.size()&&qr[j+1].fi==qr[i].fi){
  40. j++;
  41. if(qr[j].se.fi==1) tl.push_back(qr[j].se.se);
  42. else tr.push_back(qr[j].se.se);
  43. }
  44. if(now.size()==1&&tl.size()) ++ans[*now.begin()];
  45. for(int it:tl) now.insert(it);
  46. for(int it:tr) now.erase(it);
  47. i=j;
  48. }
  49. }
  50.  
  51. void solve(){
  52. int n;
  53. cin>>n;
  54. vector<pi> a(n);
  55. for(int i=0;i<n;i++){
  56. scanf("%d%d",&a[i].fi,&a[i].se);
  57. }
  58. vector<pair<int,pi>>qr;
  59. for(int i=0;i<n;i++){
  60. qr.push_back({a[i].fi,{1,i}});
  61. qr.push_back({a[i].se,{-1,i}});
  62. }
  63. sort(qr.begin(),qr.end());
  64. ls.clear();
  65. int cur=get(a);
  66. vector<int> ans(n,0);
  67. process(qr,ans);
  68. forn(i,n) if(ls.count(a[i].fi)) ++ls[a[i].fi];
  69. forn(i,n) if(ls[a[i].fi]==1) --ans[i];
  70. printf("%d\n",*max_element(ans.begin(),ans.end())+cur);
  71. }
  72. int main(){
  73. int n;
  74. cin>>n;
  75. forn(i,n) solve();
  76. }
  77.  

  

Codeforces Round #613 (Div. 2) (A-E)的更多相关文章

  1. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  2. Codeforces Round #240 (Div. 2)(A -- D)

    点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...

  3. Codeforces Round #324 (Div. 2) (哥德巴赫猜想)

    题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...

  4. Codeforces Round #395 (Div. 2)(未完)

    2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...

  5. B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

    ---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...

  6. 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

    题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...

  7. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #671 (Div. 2) (A~E)

    Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...

  9. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

随机推荐

  1. 一台电脑上配置多个git的ssh key

    前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...

  2. 用赋值表达式作为bool值

    enum Status { stOk, stQuit, stError }; int main() { Status status; int n; bool b1 = (status = stOk); ...

  3. 通过 python 处理 email - Email via Python

    Email via Python 1 MIME - Multipurpose Internet Mail Extensions SMTP - Simple Message Transport Prot ...

  4. 使用requests、BeautifulSoup、线程池爬取艺龙酒店信息并保存到Excel中

    import requests import time, random, csv from fake_useragent import UserAgent from bs4 import Beauti ...

  5. JS推箱子游戏

    <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inse ...

  6. .net 微服务实践

    l  前言 本文记录了我的一次.net core 微服务架构实践经验,以及所用到的技术 l  优点 每个服务聚焦于一块业务,无论在开发阶段或是部署阶段都是独立的,更适合被各个小团队开发维护,团队对服务 ...

  7. pyHamcrest

    概念 Hamcrest是用于编写匹配器对象的框架.他提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活.Hamcrest还有很好的可扩展性,能够创建自定义的匹配器. 支持语言 ...

  8. 【STM32H7教程】第62章 STM32H7的MDMA,DMA2D和通用DMA性能比较

    完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第62章       STM32H7的MDMA,DMA2D和通 ...

  9. Django 系列

    Django基础 Django框架简介 Django 静态文件 Django request对象与ORM简介 Django路由系统 Django之视图层 Django之模板层 Django的setti ...

  10. 异常 lock buffer failed for format 0x23

    02-11 21:21:45.669625 14804 14815 W Monkey : // java.lang.RuntimeException: lock buffer failed for f ...