设为首页 加入收藏

TOP

Codeforces Round #311 (Div. 2)(一)
2015-11-21 00:58:24 来源: 作者: 【 】 浏览:10
Tags:Codeforces Round #311 Div.

我只想说还好我没有放弃,还好我坚持下来了。

终于变成蓝名了,也许这对很多人来说并不算什么,但是对于一个打了这么多场才好不容易加分的人来说,我真的有点激动。

心脏的难受也许有点是因为晚上做题时太激动了,看别人过得那么快自己也紧张了。

后来看到有很多大神给我的建议是,初学者,手速并不是唯一重要的关键,掌握算法,一步步系统的完善它才是最重要的。

所以这一回也没有太紧张,也没有做一题看一下排名。

然后竟然第一次进了前1000,rating一下子加了220多。

希望这是一个好的开端,我还想继续下去,变得更强大!

?

?

题解:(因为C题我不会,所以把它写在了最前面)

?

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 the i-th leg is li.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-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 with 5legs 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 integers li (1?≤?li?≤?105), where li is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers di (1?≤?di?≤?200), where di is the number of energy units that Arthur spends on removing the i-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


?

题意:

xx人他买了一个不是脚的长度长短不一的桌子,它的桌子有n个脚,然后每个脚的长度分别为l[i]。

每次移动掉第i个脚所花费的力气为d[i]。

要使桌子满足稳定的条件为:

1)它是一只脚的,那么它肯定是稳的

2)它是2只脚的,那么如果两条腿长度都相同的话,那么就说明它是稳的

3)它是k只脚的,那么当脚的长度等于现在桌子中所含的最大长度的数量大于k/2时,则说明它也是稳的

然后要你求出使得桌子变得稳定的它所要付出的最少的力气。

题解:

这道题我是看别人代码,然后理解后才打出来的,不得不说别人的脑回路还真是复杂,都能写出这么复杂的代码,而我现在还只在刷刷水题,(太弱了。。。

我就大概讲一下核心的思路,其余的都在代码中注释的比较详细了:

?

int ans=inf;
    for(itr=mp.begin();itr!=mp.end();itr++){	//枚举所出现过的长度 
        int l=(*itr).first;		//l中存的是长度 
        int num=(*itr).second;	//num中存的是出现过的次数 
        int power=s[l];		//power中存的是这个长度所需要的力量数 
        int all=num;		//all中暂时储存了出现过的次数 
        for(int i=200;i>=1;i--){		//对力量进行暴力枚举 
            int nn=lower_bound(G[i].begin(),G[i].end(),l)-G[i].begin();	//这里是为了找到小于等于l的数有几个 
            all+=nn;
            power+=nn*i;
            if(all>=num*2){
                power-=i*(all-num*2+1);
                break;
            }
        }
        ans=min(ans,sum-power);
    }

首先这里的目的是为了求出所需要的最小的力量度。那么我们讲一下大概的思路:

?

我们的想法是,假设每次l都是最大的长度,然后我们在再满足题目中条件的情况下去求力量数。

这里我们采用了暴力和贪心的想法,我们 对力量进行枚举,我们要尽可能的先贪心的选取较大的力量(也就是说我们选进去的腿是不用被拆掉的)。

然后这里可以用二分求出在当前力量下小于等于l长度的有多少个。

当满足all>=num*2时,说明我们已经选多了,所以我们要减去一些腿,那么减去哪些呢?(和上面一样,也是贪心的减去当前力量下的那些桌子腿,因为它们所消耗的力量比较少。。。

因为我们这里求的是不需要减去的木棍,所以我们要求的是力量的最大值,所以题目要求的力量的最小值就是sum-power了,对吧。。

唔。。。这里还用了vector,还有迭代器,总之STL用的巧那自然是十分好的。。

?

#include
  
   
#include
   
     #include
    
      #include
     
       #include
       #include
       
         using namespace std; #define maxn 111111 #define inf 999999999 vector
        
          G[222]; //是以能量作为划分标准的; map
         
           mp; map
          
           ::iterator itr; int s[maxn]; stru
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇LintCode 字符串查找 下一篇[Leetcode]-Palindrome Number

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: