首页 > 其他分享 >D. Watch the Videos

D. Watch the Videos

时间:2023-04-06 15:44:36浏览次数:46  
标签:return cout Videos int Watch mid while false

观察找规律

最大的和二分最小的,然后交替相邻,看是否合法

找到最长的合法段

答案就是总长度减去合法段加上原先的长度

#include<bits/stdc++.h>
#define debug1(a) cout<<#a<<'='<< a << endl;
#define debug2(a,b) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<endl;
#define debug5(a,b,c,d,e) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<"  "<<#e<<" = "<<e<<endl;
#define debug0(x) cout << "debug0: " << x << endl
#define fr(t, i, n)for (long long i = t; i < n; i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fi first
#define se second
#define int long long
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;

//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)

const int N = 2e5+10;
int a[N];
int n,v;

bool check(int x)
{
    int l = 1,r = x;
    while(l < r)
    {
        //debug2(l,r);
        if(a[l] + a[r] > v)return false;
        r --;
        if(l < r && a[l] + a[r] > v)return false;
        l ++;
    }
    return true;
}

void solve() 
{
    cin >> n >> v;
    int sum = 0;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
        sum += a[i];
    }
    
    sort(a+1,a+n+1);
    
    int l = 1,r = n;
    int mid;
    while(l < r)
    {
        mid = l+r+1>> 1;
        //debug3(l,r,mid);
        if(check(mid))l = mid;
        else r = mid-1;
        
    }
    
    cout << sum + n - l + 1<< endl;
}

signed main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */

    int T = 1;//cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

标签:return,cout,Videos,int,Watch,mid,while,false
From: https://www.cnblogs.com/cfddfc/p/17292960.html

相关文章

  • #yyds干货盘点#【愚公系列】2023年04月 .NET CORE工具案例-性能监控工具WatchDog的使
    前言所谓日志(Log)是指系统所指定对象的某些操作和其操作结果按时间有序的集合。每个日志文件由日志记录组成,每条日志记录描述了一次单独的系统事件。通常情况下,系统日志是用户可以直接阅读的文本文件,其中包含了一个时间戳和一个信息或者子系统所特有的其他信息。日志文件为服务器......
  • vue数组和对象进行 watch 和 watchEffect 对比
    constarr1=ref([]);constarr2=reactive([]);constobj1=ref({});constobj2=reactive({});watchEffect(()=>{console.log("watchEffectarr1",arr1.value);console.log("watchEffectarr2",arr2)......
  • VUE watch监听器的基本使用方法详解
    1、下面代码是watch的一种简单的用法<divid="app"><inputtype="text"v-model="firstName"/></div><scriptsrc="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script><script>......
  • 4.15 vue中watch computed
    在Vue.js中,computed是一种计算属性,它能够根据依赖的数据动态计算出一个新的值。computed属性可以定义为一个函数,该函数返回需要计算的值。当它所依赖的数据发生变化时,Vue.js会自动重新计算这个值并将其更新到组件上。与computed对应的还有另外两种常见的属性,分别是meth......
  • LIVE555再学习 -- testH264VideoStreamer 源码分析
    上一篇文章我们已经讲了一部分:testH264VideoStreamer重复从H.264基本流视频文件(名为“test.264”)中读取,并使用RTP多播进行流式传输。 该程序还具有内置的RTSP服务器。Apple的“QuickTime播放器”可用于接收和播放此音频流。要使用它,让玩家打开会话的“rtsp://”URL(程序在......
  • Vue3 watch 监听函数
    1、watch函数(既要指明监视的属性,也要指明监视的回调)坑:1)监视reactive定义的响应式数据时:oldValue无法正确获取、强制开启了深度监视(deep配置失效)2)监视reactive定义的响应式数据中某个属性时:deep配置有效setup(){letsum=ref(0)letmsg=ref('ABCD')letp......
  • youtube点击位置纠偏论文:《Recommending What Video to Watch Next: A Multitask Rank
    背景在推荐系统存在两个难题:1.需要同时优化点击、观看时长、点赞、打分、评论等多个目标,如何同时建模多个目标2.存在positionbias,即同个视频放在不通位置上点击率等会不同,如何建模positionbiasyoutube这篇论文采用了MMOE来建模多目标,并用一个shallowtower来建模position......
  • Vue中watch和computed的区别和应用场景
    watch中的函数是不需要调用的,computed内部的函数调用的时候不需要加()。Watch是属性监听,监听属性的变化;computed是计算属性,通过属性计算而得来的属性。watch需要在数据变化......
  • neural-network-3b1b-watching-notes
    3B1B观看笔记Datetime:2023-03-26T23:20+08:00Categories:MachineLearningNeuralNetworksPlaylistonYoutubewhatismlp?costfunctionandparamsgradient......
  • 初识vue3-setup语法糖,ref和reactive语法,computde计算属性,watch开启监听
    vue3和vue2的区别1,vue3首次渲染更快(Vue3在编译和渲染性能上有了很大的提升,主要是因为使用了Proxy代理和优化算法,使得组件可以更快的渲染)2,diff算法更快3,内存占用体积......