zoukankan      html  css  js  c++  java
  • codeforces 557 C

    由于期末。非常久没刷题了,CF一直掉……


    这个题事实上非常简单。

    。由于做法非常easy想到嘛。。

    就是枚举max=x时,最大能保留多少价值。不断更新ans,

    结果就是全部价值和减去ans就好

    因为最大可以保留的长度是199+200,所以当max=x时。算最大能保留多少价值,

    也是一个循环算出当前长度比x小的那个桌子角的最大的那几个价值之和保留即可了,

    这里写的比較绕。。反正看看代码一下就懂了。。。

    维护一个map即可了

    比赛的时候,由于好久没刷题了。一直没想清楚,一直到比赛结束前还剩下十分钟才恍然大悟。

    复杂度是(logn+200)*n

    只是也没办法啦。要期末嘛

    C. Arthur and Table
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

    In total the table Arthur bought has n legs, the length of thei-th leg isli.

    Arthur decided to make the table stable and remove some legs. For each of them Arthur determined numberdi — the amount of energy that he spends to remove thei-th leg.

    A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

    Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

    The second line of the input contains a sequence of n integersli (1 ≤ li ≤ 105), whereli is equal to the length of thei-th leg of the table.

    The third line of the input contains a sequence of n integersdi (1 ≤ di ≤ 200), wheredi is the number of energy units that Arthur spends on removing thei-th leg off the table.

    Output

    Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

    Sample test(s)
    Input
    2
    1 5
    3 2
    
    Output
    2
    
    Input
    3
    2 4 4
    1 1 1
    
    Output
    0
    
    Input
    6
    2 2 1 1 3 3
    4 3 5 5 2 1
    
    Output
    8





    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<bitset>
    #include<climits>
    #include<list>
    #include<iomanip>
    #include<stack>
    #include<set>
    using namespace std;
    map<int,int>num;
    struct Box
    {
    	int len,val;
    }box[100010];
    bool cmp(Box one,Box two)
    {
    	return one.len<two.len;
    }
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=0;i<n;i++)
    		cin>>box[i].len;
    	for(int i=0;i<n;i++)
    		cin>>box[i].val;
    	sort(box,box+n,cmp);
    	int l=-1,r=-2,ans=-1;
    	for(int i=0;i<n;i++)
    		for(int j=i;j<n;j++)
    			if(box[j+1].len!=box[i].len)
    			{
    				for(int k=l;k<=r;k++)
    					num[box[k].val]++;
    				l=i;r=j;
    				map<int,int>::iterator it=num.end();
    				int len=j-i,sum=0;
    				while(len>0)
    				{
    					if(it==num.begin())
    						break;
    					it--;
    					for(int k=0;k<it->second&&len>0;k++,len--)
    						sum+=it->first;
    				}
    				for(int k=l;k<=r;k++)
    					sum+=box[k].val;
    				ans=max(ans,sum);
    				i=j;
    				break;
    			}
    	int sum=0;
    	for(int i=0;i<n;i++)
    		sum+=box[i].val;
    	cout<<sum-ans;
    }




  • 相关阅读:
    网络唤醒的尝试
    远程桌面连接修改与远程连接的痕迹清理+User Profile Service服务未能登录,无法加载用户配置文件
    web与flash结合:不出现提示,直接关闭窗口(javascript)+直接关闭,不提示
    net framework 2.0,3.0与3.5三个版本之间关系
    c#连接access2003操作必须使用一个可更新的查询解决方法
    分析网络故障慢慢来!一定要抓到真凶(有关arp)
    GridView遭遇数据类型"是/否",获取gridview的一个单元格的值并更改,附带更新GridView用法
    查询和删除表中重复数据sql语句
    hibernate学习笔记
    不要在一门技术上吊死
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7227882.html
Copyright © 2011-2022 走看看