zoukankan      html  css  js  c++  java
  • 2019-ICPC沈阳重现:7-1 A-Leftbest

    直接用set中的upper_bound!

    7-1 A-Leftbest
     

    Jack is worried about being single for his whole life, so he begins to use a famous dating app. In this app, the user is shown single men/women's photos one by one, and the user may choose between “yes” and “no”. Choosing “yes” means an invitation while choosing “no” means nothing. The photos would be shown one by one until the number of rest photos to be shown reaches zero. Of course, efficient and single Jack would always choose “yes”.

    When viewing photos, Jack would have a “fake impression point” on every photo, which is not accurate. To calculate the “true impression point” of one photo, Jack would recall the “fake impression point” of every previous photo whose “fake impression point” is larger than this photo, and regard the smallest “fake impression point” of them as the “true impression point” of this photo. Jack would like to sum the “true impression point” of all photos as the outcome of his effort.

    Note that if such a larger “fake impression point” does not exist, the “true impression point” of this photo is zero.

    Input

    The first line contains an integer (1) --- the number of photos.

    The second line contains n integers a1​​, a2​​, …, an​​ where ai​​ (0) is the “fake impression point” of the i-th photo.

    Output

    Output a single integer --- the sum of the “true impression point” of all photos.

    Sample Input

    4
    2 1 4 3
    
     

    Sample Output

    6
    分析:set可是有序的哦!寻找每个数左边比他大的最小的数,累计加之————>
    
    

    修改后AC的代码:

    
    
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main()
    {
    	int n,x;
    	ll ans=0;
    	set<int> s;
    	cin>>n;
    	for(int i=0;i<n;i++)
    	{
    		cin>>x;
    		s.insert(x);
    		set<int>::iterator pos=s.upper_bound(x);
    		if(pos!=s.end())
    		{
    			ans+=*pos;
    		}
    		else ans+=0;
    	}
    	cout<<ans<<endl;
    }
    

      

    
    
    
     
  • 相关阅读:
    Java开发桌面程序学习(12)——Javafx 悬浮窗提示 tooptip
    Java开发桌面程序学习(11)——javafx 鼠标点击,右击,双击
    Web前端—— JQuery迷你版实现以及使用
    Web前端——表单提交和Js添加选项
    Web前端——JavaScript练习
    Web前端——JavaScript笔记
    <亲测>CentOS7中使用yum安装Nginx的方法
    Linux 软件安装到 /usr,/usr/local/ 还是 /opt 目录?
    <亲测>centos安装 .net core 2.1
    <亲测>CentOS7 安装mysql8.0(YUM方式)
  • 原文地址:https://www.cnblogs.com/dragondragon/p/12516022.html
Copyright © 2011-2022 走看看